Skip to content

Commit 02e3c28

Browse files
hansonrhansonr
authored andcommitted
Adds Math.ulp, nextUp
1 parent 2561b9c commit 02e3c28

File tree

1 file changed

+116
-24
lines changed

1 file changed

+116
-24
lines changed

sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js

Lines changed: 116 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3222,26 +3222,118 @@ Math.signum||(Math.signum=function(d){return(d==0.0||isNaN(d))?d:d < 0 ? -1 : 1}
32223222

32233223
Math.scalb||(Math.scalb=function(d,scaleFactor){return d*Math.pow(2,scaleFactor)});
32243224

3225-
//the following Math functions rely on datatypes nonexistant in javascript
3226-
Math.nextAfter||(Math.nextAfter=function(start,direction){return 0});
3227-
Math.nextUp||(Math.nextUp=function(d){return 0});
3228-
Math.ulp||(Math.ulp=function(d){return 0});
3229-
Math.getExponent||(Math.getExponent=function(d){return 0});
3230-
Math.IEEEremainder||(Math.IEEEremainder=function (x, y) {
3231-
if (Double.isNaN$D(x) || Double.isNaN$D(y) || Double.isInfinite$D(x) || y == 0)
3232-
return NaN;
3233-
if (!Double.isInfinite$D(x) && Double.isInfinite$D(y))
3234-
return x;
3235-
var modxy = x % y;
3236-
if (modxy == 0) return modxy;
3237-
var rem = modxy - Math.abs(y) * Math.signum(x);
3238-
if (Math.abs(rem) == Math.abs(modxy)) {
3239-
var div = x / y;
3240-
return (Math.abs(Math.round(div)) > Math.abs(div) ? rem : modxy);
3225+
//var
3226+
a64 = null, a32 = null, i32 = null, i64 = null;
3227+
3228+
Math.nextAfter||
3229+
(Math.nextAfter=function(start,direction){
3230+
if (isNaN(start) || isNaN(direction))
3231+
return NaN;
3232+
if (direction == start)
3233+
return start;
3234+
if (start == Double.MAX_VALUE && direction == Double.POSITIVE_INFINITY)
3235+
return Double.POSITIVE_INFINITY;
3236+
if (start == -Double.MAX_VALUE && direction == Double.NEGATIVE_INFINITY)
3237+
return Double.NEGATIVE_INFINITY;
3238+
if (start == Double.POSITIVE_INFINITY && direction == Double.NEGATIVE_INFINITY)
3239+
return Double.MAX_VALUE;
3240+
if (start == Double.NEGATIVE_INFINITY && direction == Double.POSITIVE_INFINITY)
3241+
return -Double.MAX_VALUE;
3242+
if (start == 0)
3243+
return (direction > 0 ? Double.MIN_VALUE : -Double.MIN_VALUE);
3244+
3245+
if (!a64) {
3246+
a64 = new Float64Array(1);
3247+
i64 = new Uint32Array(a64.buffer);
32413248
}
3242-
return (Math.abs(rem) < Math.abs(modxy) ? rem : modxy);
3249+
a64[0] = start;
3250+
var i0 = i64[0];
3251+
var i1 = i64[1];
3252+
var carry;
3253+
if ((direction > start) == (start >= 0)) {
3254+
i64[0]++;
3255+
carry = (i64[0] == 0 ? 1 : 0);
3256+
} else {
3257+
i64[0]--;
3258+
carry = (i64[0] == 4294967295 ? -1 : 0);
3259+
}
3260+
if (carry)
3261+
i64[1]+=carry;
3262+
return a64[0];
32433263
});
32443264

3265+
Math.nextAfter$D$D = Math.nextAfter;
3266+
3267+
Math.nextAfter$F$D =function(start,direction){
3268+
if (isNaN(start) || isNaN(direction))
3269+
return NaN;
3270+
if (direction == start)
3271+
return start;
3272+
if (start == Float.MAX_VALUE && direction == Float.POSITIVE_INFINITY)
3273+
return Float.POSITIVE_INFINITY;
3274+
if (start == -Float.MAX_VALUE && direction == Float.NEGATIVE_INFINITY)
3275+
return Float.NEGATIVE_INFINITY;
3276+
if (start == Float.POSITIVE_INFINITY && direction == Float.NEGATIVE_INFINITY)
3277+
return Float.MAX_VALUE;
3278+
if (start == Float.NEGATIVE_INFINITY && direction == Float.POSITIVE_INFINITY)
3279+
return -Float.MAX_VALUE;
3280+
if (start == 0 && direction < 0)
3281+
return -Float.MIN_VALUE;
3282+
if (start == 0)
3283+
return (direction > 0 ? Float.MIN_VALUE : -Float.MIN_VALUE);
3284+
3285+
if (!i32) {
3286+
a32 = new Float32Array(1);
3287+
i32 = new Int32Array(a32.buffer);
3288+
}
3289+
a32[0] = start;
3290+
i32[0] += ((direction > start) == (start >= 0) ? 1 : -1);
3291+
return a32[0];
3292+
};
3293+
3294+
3295+
Math.nextUp||(Math.nextUp=function(d){ return Math.nextAfter(d, Double.POSITIVE_INFINITY); });
3296+
3297+
Math.nextUP$D=Math.nextUp;
3298+
3299+
Math.nextUp$F = function(f){ return Math.nextAfter$F$D(f, Double.NEGATIVE_INFINITY); };
3300+
3301+
3302+
Math.nextDown||(Math.nextDown=function(d){ return Math.nextAfter(d, Double.NEGATIVE_INFINITY); });
3303+
3304+
Math.nextDown$D=Math.nextDown;
3305+
3306+
Math.nextDown$F = function(f){ return Math.nextAfter$F$D(f, Double.NEGATIVE_INFINITY); };
3307+
3308+
3309+
Math.ulp||(Math.ulp=function(d){
3310+
if (isNaN(d)) {
3311+
return Double.NaN;
3312+
}
3313+
if (isInfinite(d)) {
3314+
return Double.POSITIVE_INFINITY;
3315+
}
3316+
if (d == Double.MAX_VALUE || d == -Double.MAX_VALUE) {
3317+
return Math.pow(2, 971);
3318+
}
3319+
return Math.nextUp(Math.abs(d));
3320+
});
3321+
3322+
Math.ulp$D = Math.ulp;
3323+
3324+
Math.ulp$F = function(f){
3325+
if (isNaN(f)) {
3326+
return Float.NaN;
3327+
}
3328+
if (isInfinite(f)) {
3329+
return Float.POSITIVE_INFINITY;
3330+
}
3331+
if (f == Float.MAX_VALUE || f == -Float.MAX_VALUE) {
3332+
return Math.pow(2, 104);
3333+
}
3334+
return Math.nextUp$F(Math.abs(f));
3335+
};
3336+
32453337

32463338
Clazz._setDeclared("java.lang.Number", java.lang.Number=Number);
32473339
Number.prototype._numberToString=Number.prototype.toString;
@@ -3695,18 +3787,18 @@ return"class java.lang.Float";
36953787
return Clazz._floatToString(this.valueOf());
36963788
};
36973789

3698-
Clazz._a32 = null;
3790+
var a32, i32;
36993791

37003792
Float.floatToIntBits$F = function(f) {
3701-
var a = Clazz._a32 || (Clazz._a32 = new Float32Array(1));
3702-
a[0] = f;
3703-
return new Int32Array(a.buffer)[0];
3793+
i32 || (a32 = new Float32Array(1), i32 = new Int32Array(a32.buffer));
3794+
a32[0] = f;
3795+
return i32[0];
37043796
}
37053797

37063798
Float.intBitsToFloat$I = function(i) {
3707-
var a = Clazz._i32 || (Clazz._i32 = new Int32Array(1));
3708-
a[0] = i;
3709-
return new Float32Array(a.buffer)[0];
3799+
i32 || (a32 = new Float32Array(1), i32 = new Int32Array(a32.buffer));
3800+
i32[0] = i;
3801+
return a32[0];
37103802
}
37113803

37123804
Float.serialVersionUID=Float.prototype.serialVersionUID=-2671257302660747028;

0 commit comments

Comments
 (0)