Skip to content

Instantly share code, notes, and snippets.

@mloza
Last active March 31, 2021 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mloza/4c4e135c062ad67738340ae19da1fec2 to your computer and use it in GitHub Desktop.
Save mloza/4c4e135c062ad67738340ae19da1fec2 to your computer and use it in GitHub Desktop.
Kod do wpisu o nowościach o Javie 16 dostępny pod adresem: https://blog.mloza.pl/java-16-co-nowego/
package com.example.geometry;
public abstract sealed class Shape
permits Circle, Rectangle, Square { ... }
public final class Circle extends Shape { ... }
public sealed class Rectangle extends Shape
permits TransparentRectangle, FilledRectangle { ... }
public final class TransparentRectangle extends Rectangle { ... }
public final class FilledRectangle extends Rectangle { ... }
public non-sealed class Square extends Shape { ... }
static final VectorSpecies<Float> SPECIES = FloatVector.SPECIES_256;
void vectorComputation(float[] a, float[] b, float[] c) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
var m = SPECIES.indexInRange(i, a.length);
// FloatVector va, vb, vc;
var va = FloatVector.fromArray(SPECIES, a, i, m);
var vb = FloatVector.fromArray(SPECIES, b, i, m);
var vc = va.mul(va).
add(vb.mul(vb)).
neg();
vc.intoArray(c, i, m);
}
}
void scalarComputation(float[] a, float[] b, float[] c) {
for (int i = 0; i < a.length; i++) {
c[i] = (a[i] * a[i] + b[i] * b[i]) * -1.0f;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment