mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-31 12:24:10 -08:00
classlib: more fixes to Math.nextUp/nextDown (#746)
This commit is contained in:
parent
617ce67871
commit
154bf7abd9
|
@ -387,6 +387,9 @@ public final class TMath extends TObject {
|
||||||
if (TDouble.isNaN(d) || d == TDouble.POSITIVE_INFINITY) {
|
if (TDouble.isNaN(d) || d == TDouble.POSITIVE_INFINITY) {
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
if (d == 0.0d) {
|
||||||
|
return Double.MIN_VALUE;
|
||||||
|
}
|
||||||
long bits = TDouble.doubleToLongBits(d);
|
long bits = TDouble.doubleToLongBits(d);
|
||||||
if (d < 0) {
|
if (d < 0) {
|
||||||
bits--;
|
bits--;
|
||||||
|
@ -400,6 +403,9 @@ public final class TMath extends TObject {
|
||||||
if (TFloat.isNaN(d) || d == TFloat.POSITIVE_INFINITY) {
|
if (TFloat.isNaN(d) || d == TFloat.POSITIVE_INFINITY) {
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
if (d == 0) {
|
||||||
|
return Float.MIN_VALUE;
|
||||||
|
}
|
||||||
int bits = TFloat.floatToIntBits(d);
|
int bits = TFloat.floatToIntBits(d);
|
||||||
if (d < 0) {
|
if (d < 0) {
|
||||||
bits--;
|
bits--;
|
||||||
|
@ -417,7 +423,7 @@ public final class TMath extends TObject {
|
||||||
return -Double.MIN_VALUE;
|
return -Double.MIN_VALUE;
|
||||||
}
|
}
|
||||||
long bits = TDouble.doubleToLongBits(d);
|
long bits = TDouble.doubleToLongBits(d);
|
||||||
if (d <= 0) {
|
if (d < 0) {
|
||||||
bits++;
|
bits++;
|
||||||
} else {
|
} else {
|
||||||
bits--;
|
bits--;
|
||||||
|
@ -433,7 +439,7 @@ public final class TMath extends TObject {
|
||||||
return -Float.MIN_VALUE;
|
return -Float.MIN_VALUE;
|
||||||
}
|
}
|
||||||
int bits = TFloat.floatToIntBits(d);
|
int bits = TFloat.floatToIntBits(d);
|
||||||
if (d <= 0) {
|
if (d < 0) {
|
||||||
bits++;
|
bits++;
|
||||||
} else {
|
} else {
|
||||||
bits--;
|
bits--;
|
||||||
|
|
|
@ -106,8 +106,12 @@ public class MathTest {
|
||||||
public void nextWorks() {
|
public void nextWorks() {
|
||||||
assertEquals(Double.valueOf(-Double.MIN_VALUE), Double.valueOf(Math.nextDown(0.0)));
|
assertEquals(Double.valueOf(-Double.MIN_VALUE), Double.valueOf(Math.nextDown(0.0)));
|
||||||
assertEquals(Double.valueOf(Double.MIN_VALUE), Double.valueOf(Math.nextUp(0.0)));
|
assertEquals(Double.valueOf(Double.MIN_VALUE), Double.valueOf(Math.nextUp(0.0)));
|
||||||
|
assertEquals(Double.valueOf(-Double.MIN_VALUE), Double.valueOf(Math.nextDown(-0.0)));
|
||||||
|
assertEquals(Double.valueOf(Double.MIN_VALUE), Double.valueOf(Math.nextUp(-0.0)));
|
||||||
assertEquals(Float.valueOf(-Float.MIN_VALUE), Float.valueOf(Math.nextDown(0.0f)));
|
assertEquals(Float.valueOf(-Float.MIN_VALUE), Float.valueOf(Math.nextDown(0.0f)));
|
||||||
assertEquals(Float.valueOf(Float.MIN_VALUE), Float.valueOf(Math.nextUp(0.0f)));
|
assertEquals(Float.valueOf(Float.MIN_VALUE), Float.valueOf(Math.nextUp(0.0f)));
|
||||||
|
assertEquals(Float.valueOf(-Float.MIN_VALUE), Float.valueOf(Math.nextDown(-0.0f)));
|
||||||
|
assertEquals(Float.valueOf(Float.MIN_VALUE), Float.valueOf(Math.nextUp(-0.0f)));
|
||||||
assertEquals(Double.valueOf(0.10000000000000002), Double.valueOf(Math.nextUp(0.1)));
|
assertEquals(Double.valueOf(0.10000000000000002), Double.valueOf(Math.nextUp(0.1)));
|
||||||
assertEquals(Double.valueOf(0.9999999999999999), Double.valueOf(Math.nextDown(1.0)));
|
assertEquals(Double.valueOf(0.9999999999999999), Double.valueOf(Math.nextDown(1.0)));
|
||||||
assertEquals(Double.valueOf(-0.09999999999999999), Double.valueOf(Math.nextUp(-0.1)));
|
assertEquals(Double.valueOf(-0.09999999999999999), Double.valueOf(Math.nextUp(-0.1)));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user