bugged
stringlengths 6
599k
| fixed
stringlengths 6
40.8M
| __index_level_0__
int64 0
3.24M
|
|---|---|---|
public static double asin(double x) { boolean negative = x < 0; if (negative) x = -x; if (!(x <= 1)) return Double.NaN; if (x == 1) return negative ? -PI / 2 : PI / 2; if (x < 0.5) { if (x < 1 / TWO_27) return negative ? -x : x; double t = x * x; double p = t * (PS0 + t * (PS1 + t * (PS2 + t * (PS3 + t * (PS4 + t * PS5))))); double q = 1 + t * (QS1 + t * (QS2 + t * (QS3 + t * QS4))); return negative ? -x - x * (p / q) : x + x * (p / q); } double w = 1 - x; // 1>|x|>=0.5. double t = w * 0.5; double p = t * (PS0 + t * (PS1 + t * (PS2 + t * (PS3 + t * (PS4 + t * PS5))))); double q = 1 + t * (QS1 + t * (QS2 + t * (QS3 + t * QS4))); double s = sqrt(t); if (x >= 0.975) { w = p / q; t = PI / 2 - (2 * (s + s * w) - PI_L / 2); } else { w = (float) s; double c = (t - w * w) / (s + w); p = 2 * s * (p / q) - (PI_L / 2 - 2 * c); q = PI / 4 - 2 * w; t = PI / 4 - (p - q); } return negative ? -t : t; }
|
public static double asin(double x) { boolean negative = x < 0; if (negative) x = -x; if (!(x <= 1)) return Double.NaN; if (x == 1) return negative ? -PI / 2 : PI / 2; if (x < 0.5) { if (x < 1 / TWO_27) return negative ? -x : x; double t = x * x; double p = t * (PS0 + t * (PS1 + t * (PS2 + t * (PS3 + t * (PS4 + t * PS5))))); double q = 1 + t * (QS1 + t * (QS2 + t * (QS3 + t * QS4))); return negative ? -x - x * (p / q) : x + x * (p / q); } double w = 1 - x; // 1>|x|>=0.5. double t = w * 0.5; double p = t * (PS0 + t * (PS1 + t * (PS2 + t * (PS3 + t * (PS4 + t * PS5))))); double q = 1 + t * (QS1 + t * (QS2 + t * (QS3 + t * QS4))); double s = sqrt(t); if (x >= 0.975) { w = p / q; t = PI / 2 - (2 * (s + s * w) - PI_L / 2); } else { w = (float) s; double c = (t - w * w) / (s + w); p = 2 * s * (p / q) - (PI_L / 2 - 2 * c); q = PI / 4 - 2 * w; t = PI / 4 - (p - q); } return negative ? -t : t; }
| 2,238
|
public static double asin(double x) { boolean negative = x < 0; if (negative) x = -x; if (!(x <= 1)) return Double.NaN; if (x == 1) return negative ? -PI / 2 : PI / 2; if (x < 0.5) { if (x < 1 / TWO_27) return negative ? -x : x; double t = x * x; double p = t * (PS0 + t * (PS1 + t * (PS2 + t * (PS3 + t * (PS4 + t * PS5))))); double q = 1 + t * (QS1 + t * (QS2 + t * (QS3 + t * QS4))); return negative ? -x - x * (p / q) : x + x * (p / q); } double w = 1 - x; // 1>|x|>=0.5. double t = w * 0.5; double p = t * (PS0 + t * (PS1 + t * (PS2 + t * (PS3 + t * (PS4 + t * PS5))))); double q = 1 + t * (QS1 + t * (QS2 + t * (QS3 + t * QS4))); double s = sqrt(t); if (x >= 0.975) { w = p / q; t = PI / 2 - (2 * (s + s * w) - PI_L / 2); } else { w = (float) s; double c = (t - w * w) / (s + w); p = 2 * s * (p / q) - (PI_L / 2 - 2 * c); q = PI / 4 - 2 * w; t = PI / 4 - (p - q); } return negative ? -t : t; }
|
public static double asin(double x) { boolean negative = x < 0; if (negative) x = -x; if (!(x <= 1)) return Double.NaN; if (x == 1) return negative ? -PI / 2 : PI / 2; if (x < 0.5) { if (x < 1 / TWO_27) return negative ? -x : x; double t = x * x; double p = t * (PS0 + t * (PS1 + t * (PS2 + t * (PS3 + t * (PS4 + t * PS5))))); double q = 1 + t * (QS1 + t * (QS2 + t * (QS3 + t * QS4))); return negative ? -x - x * (p / q) : x + x * (p / q); } double w = 1 - x; // 1>|x|>=0.5. double t = w * 0.5; double p = t * (PS0 + t * (PS1 + t * (PS2 + t * (PS3 + t * (PS4 + t * PS5))))); double q = 1 + t * (QS1 + t * (QS2 + t * (QS3 + t * QS4))); double s = sqrt(t); if (x >= 0.975) { w = p / q; t = PI / 2 - (2 * (s + s * w) - PI_L / 2); } else { w = (float) s; double c = (t - w * w) / (s + w); p = 2 * s * (p / q) - (PI_L / 2 - 2 * c); q = PI / 4 - 2 * w; t = PI / 4 - (p - q); } return negative ? -t : t; }
| 2,239
|
public static double asin(double x) { boolean negative = x < 0; if (negative) x = -x; if (!(x <= 1)) return Double.NaN; if (x == 1) return negative ? -PI / 2 : PI / 2; if (x < 0.5) { if (x < 1 / TWO_27) return negative ? -x : x; double t = x * x; double p = t * (PS0 + t * (PS1 + t * (PS2 + t * (PS3 + t * (PS4 + t * PS5))))); double q = 1 + t * (QS1 + t * (QS2 + t * (QS3 + t * QS4))); return negative ? -x - x * (p / q) : x + x * (p / q); } double w = 1 - x; // 1>|x|>=0.5. double t = w * 0.5; double p = t * (PS0 + t * (PS1 + t * (PS2 + t * (PS3 + t * (PS4 + t * PS5))))); double q = 1 + t * (QS1 + t * (QS2 + t * (QS3 + t * QS4))); double s = sqrt(t); if (x >= 0.975) { w = p / q; t = PI / 2 - (2 * (s + s * w) - PI_L / 2); } else { w = (float) s; double c = (t - w * w) / (s + w); p = 2 * s * (p / q) - (PI_L / 2 - 2 * c); q = PI / 4 - 2 * w; t = PI / 4 - (p - q); } return negative ? -t : t; }
|
public static double asin(double x) { boolean negative = x < 0; if (negative) x = -x; if (!(x <= 1)) return Double.NaN; if (x == 1) return negative ? -PI / 2 : PI / 2; if (x < 0.5) { if (x < 1 / TWO_27) return negative ? -x : x; double t = x * x; double p = t * (PS0 + t * (PS1 + t * (PS2 + t * (PS3 + t * (PS4 + t * PS5))))); double q = 1 + t * (QS1 + t * (QS2 + t * (QS3 + t * QS4))); return negative ? -x - x * (p / q) : x + x * (p / q); } double w = 1 - x; // 1>|x|>=0.5. double t = w * 0.5; double p = t * (PS0 + t * (PS1 + t * (PS2 + t * (PS3 + t * (PS4 + t * PS5))))); double q = 1 + t * (QS1 + t * (QS2 + t * (QS3 + t * QS4))); double s = sqrt(t); if (x >= 0.975) { w = p / q; t = PI / 2 - (2 * (s + s * w) - PI_L / 2); } else { w = (float) s; double c = (t - w * w) / (s + w); p = 2 * s * (p / q) - (PI_L / 2 - 2 * c); q = PI / 4 - 2 * w; t = PI / 4 - (p - q); } return negative ? -t : t; }
| 2,240
|
public static double atan(double x) { double lo; double hi; boolean negative = x < 0; if (negative) x = -x; if (x >= TWO_66) return negative ? -PI / 2 : PI / 2; if (!(x >= 0.4375)) // |x|<7/16, or NaN. { if (!(x >= 1 / TWO_29)) // Small, or NaN. return negative ? -x : x; lo = hi = 0; } else if (x < 1.1875) { if (x < 0.6875) // 7/16<=|x|<11/16. { x = (2 * x - 1) / (2 + x); hi = ATAN_0_5H; lo = ATAN_0_5L; } else // 11/16<=|x|<19/16. { x = (x - 1) / (x + 1); hi = PI / 4; lo = PI_L / 4; } } else if (x < 2.4375) // 19/16<=|x|<39/16. { x = (x - 1.5) / (1 + 1.5 * x); hi = ATAN_1_5H; lo = ATAN_1_5L; } else // 39/16<=|x|<2**66. { x = -1 / x; hi = PI / 2; lo = PI_L / 2; } // Break sum from i=0 to 10 ATi*z**(i+1) into odd and even poly. double z = x * x; double w = z * z; double s1 = z * (AT0 + w * (AT2 + w * (AT4 + w * (AT6 + w * (AT8 + w * AT10))))); double s2 = w * (AT1 + w * (AT3 + w * (AT5 + w * (AT7 + w * AT9)))); if (hi == 0) return negative ? x * (s1 + s2) - x : x - x * (s1 + s2); z = hi - ((x * (s1 + s2) - lo) - x); return negative ? -z : z; }
|
public static double atan(double x) { double lo; double hi; boolean negative = x < 0; if (negative) x = -x; if (x >= TWO_66) return negative ? -PI / 2 : PI / 2; if (!(x >= 0.4375)) // |x|<7/16, or NaN. { if (!(x >= 1 / TWO_29)) // Small, or NaN. return negative ? -x : x; lo = hi = 0; } else if (x < 1.1875) { if (x < 0.6875) // 7/16<=|x|<11/16. { x = (2 * x - 1) / (2 + x); hi = ATAN_0_5H; lo = ATAN_0_5L; } else // 11/16<=|x|<19/16. { x = (x - 1) / (x + 1); hi = PI / 4; lo = PI_L / 4; } } else if (x < 2.4375) // 19/16<=|x|<39/16. { x = (x - 1.5) / (1 + 1.5 * x); hi = ATAN_1_5H; lo = ATAN_1_5L; } else // 39/16<=|x|<2**66. { x = -1 / x; hi = PI / 2; lo = PI_L / 2; } // Break sum from i=0 to 10 ATi*z**(i+1) into odd and even poly. double z = x * x; double w = z * z; double s1 = z * (AT0 + w * (AT2 + w * (AT4 + w * (AT6 + w * (AT8 + w * AT10))))); double s2 = w * (AT1 + w * (AT3 + w * (AT5 + w * (AT7 + w * AT9)))); if (hi == 0) return negative ? x * (s1 + s2) - x : x - x * (s1 + s2); z = hi - ((x * (s1 + s2) - lo) - x); return negative ? -z : z; }
| 2,241
|
public static double atan(double x) { double lo; double hi; boolean negative = x < 0; if (negative) x = -x; if (x >= TWO_66) return negative ? -PI / 2 : PI / 2; if (!(x >= 0.4375)) // |x|<7/16, or NaN. { if (!(x >= 1 / TWO_29)) // Small, or NaN. return negative ? -x : x; lo = hi = 0; } else if (x < 1.1875) { if (x < 0.6875) // 7/16<=|x|<11/16. { x = (2 * x - 1) / (2 + x); hi = ATAN_0_5H; lo = ATAN_0_5L; } else // 11/16<=|x|<19/16. { x = (x - 1) / (x + 1); hi = PI / 4; lo = PI_L / 4; } } else if (x < 2.4375) // 19/16<=|x|<39/16. { x = (x - 1.5) / (1 + 1.5 * x); hi = ATAN_1_5H; lo = ATAN_1_5L; } else // 39/16<=|x|<2**66. { x = -1 / x; hi = PI / 2; lo = PI_L / 2; } // Break sum from i=0 to 10 ATi*z**(i+1) into odd and even poly. double z = x * x; double w = z * z; double s1 = z * (AT0 + w * (AT2 + w * (AT4 + w * (AT6 + w * (AT8 + w * AT10))))); double s2 = w * (AT1 + w * (AT3 + w * (AT5 + w * (AT7 + w * AT9)))); if (hi == 0) return negative ? x * (s1 + s2) - x : x - x * (s1 + s2); z = hi - ((x * (s1 + s2) - lo) - x); return negative ? -z : z; }
|
public static double atan(double x) { double lo; double hi; boolean negative = x < 0; if (negative) x = -x; if (x >= TWO_66) return negative ? -PI / 2 : PI / 2; if (! (x >= 0.4375)) // |x|<7/16, or NaN. { if (!(x >= 1 / TWO_29)) // Small, or NaN. return negative ? -x : x; lo = hi = 0; } else if (x < 1.1875) { if (x < 0.6875) // 7/16<=|x|<11/16. { x = (2 * x - 1) / (2 + x); hi = ATAN_0_5H; lo = ATAN_0_5L; } else // 11/16<=|x|<19/16. { x = (x - 1) / (x + 1); hi = PI / 4; lo = PI_L / 4; } } else if (x < 2.4375) // 19/16<=|x|<39/16. { x = (x - 1.5) / (1 + 1.5 * x); hi = ATAN_1_5H; lo = ATAN_1_5L; } else // 39/16<=|x|<2**66. { x = -1 / x; hi = PI / 2; lo = PI_L / 2; } // Break sum from i=0 to 10 ATi*z**(i+1) into odd and even poly. double z = x * x; double w = z * z; double s1 = z * (AT0 + w * (AT2 + w * (AT4 + w * (AT6 + w * (AT8 + w * AT10))))); double s2 = w * (AT1 + w * (AT3 + w * (AT5 + w * (AT7 + w * AT9)))); if (hi == 0) return negative ? x * (s1 + s2) - x : x - x * (s1 + s2); z = hi - ((x * (s1 + s2) - lo) - x); return negative ? -z : z; }
| 2,242
|
public static double atan(double x) { double lo; double hi; boolean negative = x < 0; if (negative) x = -x; if (x >= TWO_66) return negative ? -PI / 2 : PI / 2; if (!(x >= 0.4375)) // |x|<7/16, or NaN. { if (!(x >= 1 / TWO_29)) // Small, or NaN. return negative ? -x : x; lo = hi = 0; } else if (x < 1.1875) { if (x < 0.6875) // 7/16<=|x|<11/16. { x = (2 * x - 1) / (2 + x); hi = ATAN_0_5H; lo = ATAN_0_5L; } else // 11/16<=|x|<19/16. { x = (x - 1) / (x + 1); hi = PI / 4; lo = PI_L / 4; } } else if (x < 2.4375) // 19/16<=|x|<39/16. { x = (x - 1.5) / (1 + 1.5 * x); hi = ATAN_1_5H; lo = ATAN_1_5L; } else // 39/16<=|x|<2**66. { x = -1 / x; hi = PI / 2; lo = PI_L / 2; } // Break sum from i=0 to 10 ATi*z**(i+1) into odd and even poly. double z = x * x; double w = z * z; double s1 = z * (AT0 + w * (AT2 + w * (AT4 + w * (AT6 + w * (AT8 + w * AT10))))); double s2 = w * (AT1 + w * (AT3 + w * (AT5 + w * (AT7 + w * AT9)))); if (hi == 0) return negative ? x * (s1 + s2) - x : x - x * (s1 + s2); z = hi - ((x * (s1 + s2) - lo) - x); return negative ? -z : z; }
|
public static double atan(double x) { double lo; double hi; boolean negative = x < 0; if (negative) x = -x; if (x >= TWO_66) return negative ? -PI / 2 : PI / 2; if (!(x >= 0.4375)) // |x|<7/16, or NaN. { if (! (x >= 1 / TWO_29)) // Small, or NaN. return negative ? -x : x; lo = hi = 0; } else if (x < 1.1875) { if (x < 0.6875) // 7/16<=|x|<11/16. { x = (2 * x - 1) / (2 + x); hi = ATAN_0_5H; lo = ATAN_0_5L; } else // 11/16<=|x|<19/16. { x = (x - 1) / (x + 1); hi = PI / 4; lo = PI_L / 4; } } else if (x < 2.4375) // 19/16<=|x|<39/16. { x = (x - 1.5) / (1 + 1.5 * x); hi = ATAN_1_5H; lo = ATAN_1_5L; } else // 39/16<=|x|<2**66. { x = -1 / x; hi = PI / 2; lo = PI_L / 2; } // Break sum from i=0 to 10 ATi*z**(i+1) into odd and even poly. double z = x * x; double w = z * z; double s1 = z * (AT0 + w * (AT2 + w * (AT4 + w * (AT6 + w * (AT8 + w * AT10))))); double s2 = w * (AT1 + w * (AT3 + w * (AT5 + w * (AT7 + w * AT9)))); if (hi == 0) return negative ? x * (s1 + s2) - x : x - x * (s1 + s2); z = hi - ((x * (s1 + s2) - lo) - x); return negative ? -z : z; }
| 2,243
|
public static double atan(double x) { double lo; double hi; boolean negative = x < 0; if (negative) x = -x; if (x >= TWO_66) return negative ? -PI / 2 : PI / 2; if (!(x >= 0.4375)) // |x|<7/16, or NaN. { if (!(x >= 1 / TWO_29)) // Small, or NaN. return negative ? -x : x; lo = hi = 0; } else if (x < 1.1875) { if (x < 0.6875) // 7/16<=|x|<11/16. { x = (2 * x - 1) / (2 + x); hi = ATAN_0_5H; lo = ATAN_0_5L; } else // 11/16<=|x|<19/16. { x = (x - 1) / (x + 1); hi = PI / 4; lo = PI_L / 4; } } else if (x < 2.4375) // 19/16<=|x|<39/16. { x = (x - 1.5) / (1 + 1.5 * x); hi = ATAN_1_5H; lo = ATAN_1_5L; } else // 39/16<=|x|<2**66. { x = -1 / x; hi = PI / 2; lo = PI_L / 2; } // Break sum from i=0 to 10 ATi*z**(i+1) into odd and even poly. double z = x * x; double w = z * z; double s1 = z * (AT0 + w * (AT2 + w * (AT4 + w * (AT6 + w * (AT8 + w * AT10))))); double s2 = w * (AT1 + w * (AT3 + w * (AT5 + w * (AT7 + w * AT9)))); if (hi == 0) return negative ? x * (s1 + s2) - x : x - x * (s1 + s2); z = hi - ((x * (s1 + s2) - lo) - x); return negative ? -z : z; }
|
public static double atan(double x) { double lo; double hi; boolean negative = x < 0; if (negative) x = -x; if (x >= TWO_66) return negative ? -PI / 2 : PI / 2; if (!(x >= 0.4375)) // |x|<7/16, or NaN. { if (!(x >= 1 / TWO_29)) // Small, or NaN. return negative ? -x : x; lo = hi = 0; } else if (x < 1.1875) { if (x < 0.6875) // 7/16<=|x|<11/16. { x = (2 * x - 1) / (2 + x); hi = ATAN_0_5H; lo = ATAN_0_5L; } else // 11/16<=|x|<19/16. { x = (x - 1) / (x + 1); hi = PI / 4; lo = PI_L / 4; } } else if (x < 2.4375) // 19/16<=|x|<39/16. { x = (x - 1.5) / (1 + 1.5 * x); hi = ATAN_1_5H; lo = ATAN_1_5L; } else // 39/16<=|x|<2**66. { x = -1 / x; hi = PI / 2; lo = PI_L / 2; } // Break sum from i=0 to 10 ATi*z**(i+1) into odd and even poly. double z = x * x; double w = z * z; double s1 = z * (AT0 + w * (AT2 + w * (AT4 + w * (AT6 + w * (AT8 + w * AT10))))); double s2 = w * (AT1 + w * (AT3 + w * (AT5 + w * (AT7 + w * AT9)))); if (hi == 0) return negative ? x * (s1 + s2) - x : x - x * (s1 + s2); z = hi - ((x * (s1 + s2) - lo) - x); return negative ? -z : z; }
| 2,244
|
public static double atan(double x) { double lo; double hi; boolean negative = x < 0; if (negative) x = -x; if (x >= TWO_66) return negative ? -PI / 2 : PI / 2; if (!(x >= 0.4375)) // |x|<7/16, or NaN. { if (!(x >= 1 / TWO_29)) // Small, or NaN. return negative ? -x : x; lo = hi = 0; } else if (x < 1.1875) { if (x < 0.6875) // 7/16<=|x|<11/16. { x = (2 * x - 1) / (2 + x); hi = ATAN_0_5H; lo = ATAN_0_5L; } else // 11/16<=|x|<19/16. { x = (x - 1) / (x + 1); hi = PI / 4; lo = PI_L / 4; } } else if (x < 2.4375) // 19/16<=|x|<39/16. { x = (x - 1.5) / (1 + 1.5 * x); hi = ATAN_1_5H; lo = ATAN_1_5L; } else // 39/16<=|x|<2**66. { x = -1 / x; hi = PI / 2; lo = PI_L / 2; } // Break sum from i=0 to 10 ATi*z**(i+1) into odd and even poly. double z = x * x; double w = z * z; double s1 = z * (AT0 + w * (AT2 + w * (AT4 + w * (AT6 + w * (AT8 + w * AT10))))); double s2 = w * (AT1 + w * (AT3 + w * (AT5 + w * (AT7 + w * AT9)))); if (hi == 0) return negative ? x * (s1 + s2) - x : x - x * (s1 + s2); z = hi - ((x * (s1 + s2) - lo) - x); return negative ? -z : z; }
|
public static double atan(double x) { double lo; double hi; boolean negative = x < 0; if (negative) x = -x; if (x >= TWO_66) return negative ? -PI / 2 : PI / 2; if (!(x >= 0.4375)) // |x|<7/16, or NaN. { if (!(x >= 1 / TWO_29)) // Small, or NaN. return negative ? -x : x; lo = hi = 0; } else if (x < 1.1875) { if (x < 0.6875) // 7/16<=|x|<11/16. { x = (2 * x - 1) / (2 + x); hi = ATAN_0_5H; lo = ATAN_0_5L; } else // 11/16<=|x|<19/16. { x = (x - 1) / (x + 1); hi = PI / 4; lo = PI_L / 4; } } else if (x < 2.4375) // 19/16<=|x|<39/16. { x = (x - 1.5) / (1 + 1.5 * x); hi = ATAN_1_5H; lo = ATAN_1_5L; } else // 39/16<=|x|<2**66. { x = -1 / x; hi = PI / 2; lo = PI_L / 2; } // Break sum from i=0 to 10 ATi*z**(i+1) into odd and even poly. double z = x * x; double w = z * z; double s1 = z * (AT0 + w * (AT2 + w * (AT4 + w * (AT6 + w * (AT8 + w * AT10))))); double s2 = w * (AT1 + w * (AT3 + w * (AT5 + w * (AT7 + w * AT9)))); if (hi == 0) return negative ? x * (s1 + s2) - x : x - x * (s1 + s2); z = hi - ((x * (s1 + s2) - lo) - x); return negative ? -z : z; }
| 2,245
|
public static double atan(double x) { double lo; double hi; boolean negative = x < 0; if (negative) x = -x; if (x >= TWO_66) return negative ? -PI / 2 : PI / 2; if (!(x >= 0.4375)) // |x|<7/16, or NaN. { if (!(x >= 1 / TWO_29)) // Small, or NaN. return negative ? -x : x; lo = hi = 0; } else if (x < 1.1875) { if (x < 0.6875) // 7/16<=|x|<11/16. { x = (2 * x - 1) / (2 + x); hi = ATAN_0_5H; lo = ATAN_0_5L; } else // 11/16<=|x|<19/16. { x = (x - 1) / (x + 1); hi = PI / 4; lo = PI_L / 4; } } else if (x < 2.4375) // 19/16<=|x|<39/16. { x = (x - 1.5) / (1 + 1.5 * x); hi = ATAN_1_5H; lo = ATAN_1_5L; } else // 39/16<=|x|<2**66. { x = -1 / x; hi = PI / 2; lo = PI_L / 2; } // Break sum from i=0 to 10 ATi*z**(i+1) into odd and even poly. double z = x * x; double w = z * z; double s1 = z * (AT0 + w * (AT2 + w * (AT4 + w * (AT6 + w * (AT8 + w * AT10))))); double s2 = w * (AT1 + w * (AT3 + w * (AT5 + w * (AT7 + w * AT9)))); if (hi == 0) return negative ? x * (s1 + s2) - x : x - x * (s1 + s2); z = hi - ((x * (s1 + s2) - lo) - x); return negative ? -z : z; }
|
public static double atan(double x) { double lo; double hi; boolean negative = x < 0; if (negative) x = -x; if (x >= TWO_66) return negative ? -PI / 2 : PI / 2; if (!(x >= 0.4375)) // |x|<7/16, or NaN. { if (!(x >= 1 / TWO_29)) // Small, or NaN. return negative ? -x : x; lo = hi = 0; } else if (x < 1.1875) { if (x < 0.6875) // 7/16<=|x|<11/16. { x = (2 * x - 1) / (2 + x); hi = ATAN_0_5H; lo = ATAN_0_5L; } else // 11/16<=|x|<19/16. { x = (x - 1) / (x + 1); hi = PI / 4; lo = PI_L / 4; } } else if (x < 2.4375) // 19/16<=|x|<39/16. { x = (x - 1.5) / (1 + 1.5 * x); hi = ATAN_1_5H; lo = ATAN_1_5L; } else // 39/16<=|x|<2**66. { x = -1 / x; hi = PI / 2; lo = PI_L / 2; } // Break sum from i=0 to 10 ATi*z**(i+1) into odd and even poly. double z = x * x; double w = z * z; double s1 = z * (AT0 + w * (AT2 + w * (AT4 + w * (AT6 + w * (AT8 + w * AT10))))); double s2 = w * (AT1 + w * (AT3 + w * (AT5 + w * (AT7 + w * AT9)))); if (hi == 0) return negative ? x * (s1 + s2) - x : x - x * (s1 + s2); z = hi - ((x * (s1 + s2) - lo) - x); return negative ? -z : z; }
| 2,246
|
public static double atan(double x) { double lo; double hi; boolean negative = x < 0; if (negative) x = -x; if (x >= TWO_66) return negative ? -PI / 2 : PI / 2; if (!(x >= 0.4375)) // |x|<7/16, or NaN. { if (!(x >= 1 / TWO_29)) // Small, or NaN. return negative ? -x : x; lo = hi = 0; } else if (x < 1.1875) { if (x < 0.6875) // 7/16<=|x|<11/16. { x = (2 * x - 1) / (2 + x); hi = ATAN_0_5H; lo = ATAN_0_5L; } else // 11/16<=|x|<19/16. { x = (x - 1) / (x + 1); hi = PI / 4; lo = PI_L / 4; } } else if (x < 2.4375) // 19/16<=|x|<39/16. { x = (x - 1.5) / (1 + 1.5 * x); hi = ATAN_1_5H; lo = ATAN_1_5L; } else // 39/16<=|x|<2**66. { x = -1 / x; hi = PI / 2; lo = PI_L / 2; } // Break sum from i=0 to 10 ATi*z**(i+1) into odd and even poly. double z = x * x; double w = z * z; double s1 = z * (AT0 + w * (AT2 + w * (AT4 + w * (AT6 + w * (AT8 + w * AT10))))); double s2 = w * (AT1 + w * (AT3 + w * (AT5 + w * (AT7 + w * AT9)))); if (hi == 0) return negative ? x * (s1 + s2) - x : x - x * (s1 + s2); z = hi - ((x * (s1 + s2) - lo) - x); return negative ? -z : z; }
|
public static double atan(double x) { double lo; double hi; boolean negative = x < 0; if (negative) x = -x; if (x >= TWO_66) return negative ? -PI / 2 : PI / 2; if (!(x >= 0.4375)) // |x|<7/16, or NaN. { if (!(x >= 1 / TWO_29)) // Small, or NaN. return negative ? -x : x; lo = hi = 0; } else if (x < 1.1875) { if (x < 0.6875) // 7/16<=|x|<11/16. { x = (2 * x - 1) / (2 + x); hi = ATAN_0_5H; lo = ATAN_0_5L; } else // 11/16<=|x|<19/16. { x = (x - 1) / (x + 1); hi = PI / 4; lo = PI_L / 4; } } else if (x < 2.4375) // 19/16<=|x|<39/16. { x = (x - 1.5) / (1 + 1.5 * x); hi = ATAN_1_5H; lo = ATAN_1_5L; } else // 39/16<=|x|<2**66. { x = -1 / x; hi = PI / 2; lo = PI_L / 2; } // Break sum from i=0 to 10 ATi*z**(i+1) into odd and even poly. double z = x * x; double w = z * z; double s1 = z * (AT0 + w * (AT2 + w * (AT4 + w * (AT6 + w * (AT8 + w * AT10))))); double s2 = w * (AT1 + w * (AT3 + w * (AT5 + w * (AT7 + w * AT9)))); if (hi == 0) return negative ? x * (s1 + s2) - x : x - x * (s1 + s2); z = hi - ((x * (s1 + s2) - lo) - x); return negative ? -z : z; }
| 2,247
|
public static double atan(double x) { double lo; double hi; boolean negative = x < 0; if (negative) x = -x; if (x >= TWO_66) return negative ? -PI / 2 : PI / 2; if (!(x >= 0.4375)) // |x|<7/16, or NaN. { if (!(x >= 1 / TWO_29)) // Small, or NaN. return negative ? -x : x; lo = hi = 0; } else if (x < 1.1875) { if (x < 0.6875) // 7/16<=|x|<11/16. { x = (2 * x - 1) / (2 + x); hi = ATAN_0_5H; lo = ATAN_0_5L; } else // 11/16<=|x|<19/16. { x = (x - 1) / (x + 1); hi = PI / 4; lo = PI_L / 4; } } else if (x < 2.4375) // 19/16<=|x|<39/16. { x = (x - 1.5) / (1 + 1.5 * x); hi = ATAN_1_5H; lo = ATAN_1_5L; } else // 39/16<=|x|<2**66. { x = -1 / x; hi = PI / 2; lo = PI_L / 2; } // Break sum from i=0 to 10 ATi*z**(i+1) into odd and even poly. double z = x * x; double w = z * z; double s1 = z * (AT0 + w * (AT2 + w * (AT4 + w * (AT6 + w * (AT8 + w * AT10))))); double s2 = w * (AT1 + w * (AT3 + w * (AT5 + w * (AT7 + w * AT9)))); if (hi == 0) return negative ? x * (s1 + s2) - x : x - x * (s1 + s2); z = hi - ((x * (s1 + s2) - lo) - x); return negative ? -z : z; }
|
public static double atan(double x) { double lo; double hi; boolean negative = x < 0; if (negative) x = -x; if (x >= TWO_66) return negative ? -PI / 2 : PI / 2; if (!(x >= 0.4375)) // |x|<7/16, or NaN. { if (!(x >= 1 / TWO_29)) // Small, or NaN. return negative ? -x : x; lo = hi = 0; } else if (x < 1.1875) { if (x < 0.6875) // 7/16<=|x|<11/16. { x = (2 * x - 1) / (2 + x); hi = ATAN_0_5H; lo = ATAN_0_5L; } else // 11/16<=|x|<19/16. { x = (x - 1) / (x + 1); hi = PI / 4; lo = PI_L / 4; } } else if (x < 2.4375) // 19/16<=|x|<39/16. { x = (x - 1.5) / (1 + 1.5 * x); hi = ATAN_1_5H; lo = ATAN_1_5L; } else // 39/16<=|x|<2**66. { x = -1 / x; hi = PI / 2; lo = PI_L / 2; } // Break sum from i=0 to 10 ATi*z**(i+1) into odd and even poly. double z = x * x; double w = z * z; double s1 = z * (AT0 + w * (AT2 + w * (AT4 + w * (AT6 + w * (AT8 + w * AT10))))); double s2 = w * (AT1 + w * (AT3 + w * (AT5 + w * (AT7 + w * AT9)))); if (hi == 0) return negative ? x * (s1 + s2) - x : x - x * (s1 + s2); z = hi - ((x * (s1 + s2) - lo) - x); return negative ? -z : z; }
| 2,248
|
public static double atan2(double y, double x) { if (x != x || y != y) return Double.NaN; if (x == 1) return atan(y); if (x == Double.POSITIVE_INFINITY) { if (y == Double.POSITIVE_INFINITY) return PI / 4; if (y == Double.NEGATIVE_INFINITY) return -PI / 4; return 0 * y; } if (x == Double.NEGATIVE_INFINITY) { if (y == Double.POSITIVE_INFINITY) return 3 * PI / 4; if (y == Double.NEGATIVE_INFINITY) return -3 * PI / 4; return (1 / (0 * y) == Double.POSITIVE_INFINITY) ? PI : -PI; } if (y == 0) { if (1 / (0 * x) == Double.POSITIVE_INFINITY) return y; return (1 / y == Double.POSITIVE_INFINITY) ? PI : -PI; } if (y == Double.POSITIVE_INFINITY || y == Double.NEGATIVE_INFINITY || x == 0) return y < 0 ? -PI / 2 : PI / 2; double z = abs(y / x); // Safe to do y/x. if (z > TWO_60) z = PI / 2 + 0.5 * PI_L; else if (x < 0 && z < 1 / TWO_60) z = 0; else z = atan(z); if (x > 0) return y > 0 ? z : -z; return y > 0 ? PI - (z - PI_L) : z - PI_L - PI; }
|
public static double atan2(double y, double x) { if (x != x || y != y) return Double.NaN; if (x == 1) return atan(y); if (x == Double.POSITIVE_INFINITY) { if (y == Double.POSITIVE_INFINITY) return PI / 4; if (y == Double.NEGATIVE_INFINITY) return -PI / 4; return 0 * y; } if (x == Double.NEGATIVE_INFINITY) { if (y == Double.POSITIVE_INFINITY) return 3 * PI / 4; if (y == Double.NEGATIVE_INFINITY) return -3 * PI / 4; return (1 / (0 * y) == Double.POSITIVE_INFINITY) ? PI : -PI; } if (y == 0) { if (1 / (0 * x) == Double.POSITIVE_INFINITY) return y; return (1 / y == Double.POSITIVE_INFINITY) ? PI : -PI; } if (y == Double.POSITIVE_INFINITY || y == Double.NEGATIVE_INFINITY || x == 0) return y < 0 ? -PI / 2 : PI / 2; double z = abs(y / x); // Safe to do y/x. if (z > TWO_60) z = PI / 2 + 0.5 * PI_L; else if (x < 0 && z < 1 / TWO_60) z = 0; else z = atan(z); if (x > 0) return y > 0 ? z : -z; return y > 0 ? PI - (z - PI_L) : z - PI_L - PI; }
| 2,249
|
public static double atan2(double y, double x) { if (x != x || y != y) return Double.NaN; if (x == 1) return atan(y); if (x == Double.POSITIVE_INFINITY) { if (y == Double.POSITIVE_INFINITY) return PI / 4; if (y == Double.NEGATIVE_INFINITY) return -PI / 4; return 0 * y; } if (x == Double.NEGATIVE_INFINITY) { if (y == Double.POSITIVE_INFINITY) return 3 * PI / 4; if (y == Double.NEGATIVE_INFINITY) return -3 * PI / 4; return (1 / (0 * y) == Double.POSITIVE_INFINITY) ? PI : -PI; } if (y == 0) { if (1 / (0 * x) == Double.POSITIVE_INFINITY) return y; return (1 / y == Double.POSITIVE_INFINITY) ? PI : -PI; } if (y == Double.POSITIVE_INFINITY || y == Double.NEGATIVE_INFINITY || x == 0) return y < 0 ? -PI / 2 : PI / 2; double z = abs(y / x); // Safe to do y/x. if (z > TWO_60) z = PI / 2 + 0.5 * PI_L; else if (x < 0 && z < 1 / TWO_60) z = 0; else z = atan(z); if (x > 0) return y > 0 ? z : -z; return y > 0 ? PI - (z - PI_L) : z - PI_L - PI; }
|
public static double atan2(double y, double x) { if (x != x || y != y) return Double.NaN; if (x == 1) return atan(y); if (x == Double.POSITIVE_INFINITY) { if (y == Double.POSITIVE_INFINITY) return PI / 4; if (y == Double.NEGATIVE_INFINITY) return -PI / 4; return 0 * y; } if (x == Double.NEGATIVE_INFINITY) { if (y == Double.POSITIVE_INFINITY) return 3 * PI / 4; if (y == Double.NEGATIVE_INFINITY) return -3 * PI / 4; return (1 / (0 * y) == Double.POSITIVE_INFINITY) ? PI : -PI; } if (y == 0) { if (1 / (0 * x) == Double.POSITIVE_INFINITY) return y; return (1 / y == Double.POSITIVE_INFINITY) ? PI : -PI; } if (y == Double.POSITIVE_INFINITY || y == Double.NEGATIVE_INFINITY || x == 0) return y < 0 ? -PI / 2 : PI / 2; double z = abs(y / x); // Safe to do y/x. if (z > TWO_60) z = PI / 2 + 0.5 * PI_L; else if (x < 0 && z < 1 / TWO_60) z = 0; else z = atan(z); if (x > 0) return y > 0 ? z : -z; return y > 0 ? PI - (z - PI_L) : z - PI_L - PI; }
| 2,250
|
public static double atan2(double y, double x) { if (x != x || y != y) return Double.NaN; if (x == 1) return atan(y); if (x == Double.POSITIVE_INFINITY) { if (y == Double.POSITIVE_INFINITY) return PI / 4; if (y == Double.NEGATIVE_INFINITY) return -PI / 4; return 0 * y; } if (x == Double.NEGATIVE_INFINITY) { if (y == Double.POSITIVE_INFINITY) return 3 * PI / 4; if (y == Double.NEGATIVE_INFINITY) return -3 * PI / 4; return (1 / (0 * y) == Double.POSITIVE_INFINITY) ? PI : -PI; } if (y == 0) { if (1 / (0 * x) == Double.POSITIVE_INFINITY) return y; return (1 / y == Double.POSITIVE_INFINITY) ? PI : -PI; } if (y == Double.POSITIVE_INFINITY || y == Double.NEGATIVE_INFINITY || x == 0) return y < 0 ? -PI / 2 : PI / 2; double z = abs(y / x); // Safe to do y/x. if (z > TWO_60) z = PI / 2 + 0.5 * PI_L; else if (x < 0 && z < 1 / TWO_60) z = 0; else z = atan(z); if (x > 0) return y > 0 ? z : -z; return y > 0 ? PI - (z - PI_L) : z - PI_L - PI; }
|
public static double atan2(double y, double x) { if (x != x || y != y) return Double.NaN; if (x == 1) return atan(y); if (x == Double.POSITIVE_INFINITY) { if (y == Double.POSITIVE_INFINITY) return PI / 4; if (y == Double.NEGATIVE_INFINITY) return -PI / 4; return 0 * y; } if (x == Double.NEGATIVE_INFINITY) { if (y == Double.POSITIVE_INFINITY) return 3 * PI / 4; if (y == Double.NEGATIVE_INFINITY) return -3 * PI / 4; return (1 / (0 * y) == Double.POSITIVE_INFINITY) ? PI : -PI; } if (y == 0) { if (1 / (0 * x) == Double.POSITIVE_INFINITY) return y; return (1 / y == Double.POSITIVE_INFINITY) ? PI : -PI; } if (y == Double.POSITIVE_INFINITY || y == Double.NEGATIVE_INFINITY || x == 0) return y < 0 ? -PI / 2 : PI / 2; double z = abs(y / x); // Safe to do y/x. if (z > TWO_60) z = PI / 2 + 0.5 * PI_L; else if (x < 0 && z < 1 / TWO_60) z = 0; else z = atan(z); if (x > 0) return y > 0 ? z : -z; return y > 0 ? PI - (z - PI_L) : z - PI_L - PI; }
| 2,251
|
public static double atan2(double y, double x) { if (x != x || y != y) return Double.NaN; if (x == 1) return atan(y); if (x == Double.POSITIVE_INFINITY) { if (y == Double.POSITIVE_INFINITY) return PI / 4; if (y == Double.NEGATIVE_INFINITY) return -PI / 4; return 0 * y; } if (x == Double.NEGATIVE_INFINITY) { if (y == Double.POSITIVE_INFINITY) return 3 * PI / 4; if (y == Double.NEGATIVE_INFINITY) return -3 * PI / 4; return (1 / (0 * y) == Double.POSITIVE_INFINITY) ? PI : -PI; } if (y == 0) { if (1 / (0 * x) == Double.POSITIVE_INFINITY) return y; return (1 / y == Double.POSITIVE_INFINITY) ? PI : -PI; } if (y == Double.POSITIVE_INFINITY || y == Double.NEGATIVE_INFINITY || x == 0) return y < 0 ? -PI / 2 : PI / 2; double z = abs(y / x); // Safe to do y/x. if (z > TWO_60) z = PI / 2 + 0.5 * PI_L; else if (x < 0 && z < 1 / TWO_60) z = 0; else z = atan(z); if (x > 0) return y > 0 ? z : -z; return y > 0 ? PI - (z - PI_L) : z - PI_L - PI; }
|
public static double atan2(double y, double x) { if (x != x || y != y) return Double.NaN; if (x == 1) return atan(y); if (x == Double.POSITIVE_INFINITY) { if (y == Double.POSITIVE_INFINITY) return PI / 4; if (y == Double.NEGATIVE_INFINITY) return -PI / 4; return 0 * y; } if (x == Double.NEGATIVE_INFINITY) { if (y == Double.POSITIVE_INFINITY) return 3 * PI / 4; if (y == Double.NEGATIVE_INFINITY) return -3 * PI / 4; return (1 / (0 * y) == Double.POSITIVE_INFINITY) ? PI : -PI; } if (y == 0) { if (1 / (0 * x) == Double.POSITIVE_INFINITY) return y; return (1 / y == Double.POSITIVE_INFINITY) ? PI : -PI; } if (y == Double.POSITIVE_INFINITY || y == Double.NEGATIVE_INFINITY || x == 0) return y < 0 ? -PI / 2 : PI / 2; double z = abs(y / x); // Safe to do y/x. if (z > TWO_60) z = PI / 2 + 0.5 * PI_L; else if (x < 0 && z < 1 / TWO_60) z = 0; else z = atan(z); if (x > 0) return y > 0 ? z : -z; return y > 0 ? PI - (z - PI_L) : z - PI_L - PI; }
| 2,252
|
public static double atan2(double y, double x) { if (x != x || y != y) return Double.NaN; if (x == 1) return atan(y); if (x == Double.POSITIVE_INFINITY) { if (y == Double.POSITIVE_INFINITY) return PI / 4; if (y == Double.NEGATIVE_INFINITY) return -PI / 4; return 0 * y; } if (x == Double.NEGATIVE_INFINITY) { if (y == Double.POSITIVE_INFINITY) return 3 * PI / 4; if (y == Double.NEGATIVE_INFINITY) return -3 * PI / 4; return (1 / (0 * y) == Double.POSITIVE_INFINITY) ? PI : -PI; } if (y == 0) { if (1 / (0 * x) == Double.POSITIVE_INFINITY) return y; return (1 / y == Double.POSITIVE_INFINITY) ? PI : -PI; } if (y == Double.POSITIVE_INFINITY || y == Double.NEGATIVE_INFINITY || x == 0) return y < 0 ? -PI / 2 : PI / 2; double z = abs(y / x); // Safe to do y/x. if (z > TWO_60) z = PI / 2 + 0.5 * PI_L; else if (x < 0 && z < 1 / TWO_60) z = 0; else z = atan(z); if (x > 0) return y > 0 ? z : -z; return y > 0 ? PI - (z - PI_L) : z - PI_L - PI; }
|
public static double atan2(double y, double x) { if (x != x || y != y) return Double.NaN; if (x == 1) return atan(y); if (x == Double.POSITIVE_INFINITY) { if (y == Double.POSITIVE_INFINITY) return PI / 4; if (y == Double.NEGATIVE_INFINITY) return -PI / 4; return 0 * y; } if (x == Double.NEGATIVE_INFINITY) { if (y == Double.POSITIVE_INFINITY) return 3 * PI / 4; if (y == Double.NEGATIVE_INFINITY) return -3 * PI / 4; return (1 / (0 * y) == Double.POSITIVE_INFINITY) ? PI : -PI; } if (y == 0) { if (1 / (0 * x) == Double.POSITIVE_INFINITY) return y; return (1 / y == Double.POSITIVE_INFINITY) ? PI : -PI; } if (y == Double.POSITIVE_INFINITY || y == Double.NEGATIVE_INFINITY || x == 0) return y < 0 ? -PI / 2 : PI / 2; double z = abs(y / x); // Safe to do y/x. if (z > TWO_60) z = PI / 2 + 0.5 * PI_L; else if (x < 0 && z < 1 / TWO_60) z = 0; else z = atan(z); if (x > 0) return y > 0 ? z : -z; return y > 0 ? PI - (z - PI_L) : z - PI_L - PI; }
| 2,253
|
public static double ceil(double a) { return -floor(-a); }
|
public static double ceil(double a) { return -floor(-a); }
| 2,254
|
public static double cos(double a) { if (a == Double.NEGATIVE_INFINITY || !(a < Double.POSITIVE_INFINITY)) return Double.NaN; if (abs(a) <= PI / 4) return cos(a, 0); // Argument reduction needed. double[] y = new double[2]; int n = remPiOver2(a, y); switch (n & 3) { case 0 : return cos(y[0], y[1]); case 1 : return -sin(y[0], y[1]); case 2 : return -cos(y[0], y[1]); default : return sin(y[0], y[1]); } }
|
public static double cos(double a) { if (a == Double.NEGATIVE_INFINITY || !(a < Double.POSITIVE_INFINITY)) return Double.NaN; if (abs(a) <= PI / 4) return cos(a, 0); // Argument reduction needed. double[] y = new double[2]; int n = remPiOver2(a, y); switch (n & 3) { case 0 : return cos(y[0], y[1]); case 1 : return -sin(y[0], y[1]); case 2 : return -cos(y[0], y[1]); default : return sin(y[0], y[1]); } }
| 2,255
|
public static double cos(double a) { if (a == Double.NEGATIVE_INFINITY || !(a < Double.POSITIVE_INFINITY)) return Double.NaN; if (abs(a) <= PI / 4) return cos(a, 0); // Argument reduction needed. double[] y = new double[2]; int n = remPiOver2(a, y); switch (n & 3) { case 0 : return cos(y[0], y[1]); case 1 : return -sin(y[0], y[1]); case 2 : return -cos(y[0], y[1]); default : return sin(y[0], y[1]); } }
|
public static double cos(double a) { if (a == Double.NEGATIVE_INFINITY || !(a < Double.POSITIVE_INFINITY)) return Double.NaN; if (abs(a) <= PI / 4) return cos(a, 0); // Argument reduction needed. double[] y = new double[2]; int n = remPiOver2(a, y); switch (n & 3) { case 0 : return cos(y[0], y[1]); case 1 : return -sin(y[0], y[1]); case 2 : return -cos(y[0], y[1]); default : return sin(y[0], y[1]); } }
| 2,256
|
public static double cos(double a) { if (a == Double.NEGATIVE_INFINITY || !(a < Double.POSITIVE_INFINITY)) return Double.NaN; if (abs(a) <= PI / 4) return cos(a, 0); // Argument reduction needed. double[] y = new double[2]; int n = remPiOver2(a, y); switch (n & 3) { case 0 : return cos(y[0], y[1]); case 1 : return -sin(y[0], y[1]); case 2 : return -cos(y[0], y[1]); default : return sin(y[0], y[1]); } }
|
public static double cos(double a) { if (a == Double.NEGATIVE_INFINITY || !(a < Double.POSITIVE_INFINITY)) return Double.NaN; if (abs(a) <= PI / 4) return cos(a, 0); // Argument reduction needed. double[] y = new double[2]; int n = remPiOver2(a, y); switch (n & 3) { case 0 : return cos(y[0], y[1]); case 1 : return -sin(y[0], y[1]); case 2 : return -cos(y[0], y[1]); default : return sin(y[0], y[1]); } }
| 2,257
|
public static double cos(double a) { if (a == Double.NEGATIVE_INFINITY || !(a < Double.POSITIVE_INFINITY)) return Double.NaN; if (abs(a) <= PI / 4) return cos(a, 0); // Argument reduction needed. double[] y = new double[2]; int n = remPiOver2(a, y); switch (n & 3) { case 0 : return cos(y[0], y[1]); case 1 : return -sin(y[0], y[1]); case 2 : return -cos(y[0], y[1]); default : return sin(y[0], y[1]); } }
|
public static double cos(double a) { if (a == Double.NEGATIVE_INFINITY || !(a < Double.POSITIVE_INFINITY)) return Double.NaN; if (abs(a) <= PI / 4) return cos(a, 0); // Argument reduction needed. double[] y = new double[2]; int n = remPiOver2(a, y); switch (n & 3) { case 0 : return cos(y[0], y[1]); case 1 : return -sin(y[0], y[1]); case 2 : return -cos(y[0], y[1]); default : return sin(y[0], y[1]); } }
| 2,258
|
public static double cos(double a) { if (a == Double.NEGATIVE_INFINITY || !(a < Double.POSITIVE_INFINITY)) return Double.NaN; if (abs(a) <= PI / 4) return cos(a, 0); // Argument reduction needed. double[] y = new double[2]; int n = remPiOver2(a, y); switch (n & 3) { case 0 : return cos(y[0], y[1]); case 1 : return -sin(y[0], y[1]); case 2 : return -cos(y[0], y[1]); default : return sin(y[0], y[1]); } }
|
public static double cos(double a) { if (a == Double.NEGATIVE_INFINITY || !(a < Double.POSITIVE_INFINITY)) return Double.NaN; if (abs(a) <= PI / 4) return cos(a, 0); // Argument reduction needed. double[] y = new double[2]; int n = remPiOver2(a, y); switch (n & 3) { case 0 : return cos(y[0], y[1]); case 1 : return -sin(y[0], y[1]); case 2 : return -cos(y[0], y[1]); default : return sin(y[0], y[1]); } }
| 2,259
|
public static double exp(double x) { if (x != x) return x; if (x > EXP_LIMIT_H) return Double.POSITIVE_INFINITY; if (x < EXP_LIMIT_L) return 0; // Argument reduction. double hi; double lo; int k; double t = abs(x); if (t > 0.5 * LN2) { if (t < 1.5 * LN2) { hi = t - LN2_H; lo = LN2_L; k = 1; } else { k = (int) (INV_LN2 * t + 0.5); hi = t - k * LN2_H; lo = k * LN2_L; } if (x < 0) { hi = -hi; lo = -lo; k = -k; } x = hi - lo; } else if (t < 1 / TWO_28) return 1; else lo = hi = k = 0; // Now x is in primary range. t = x * x; double c = x - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); if (k == 0) return 1 - (x * c / (c - 2) - x); double y = 1 - (lo - x * c / (2 - c) - hi); return scale(y, k); }
|
public static double exp(double x) { if (x != x) return x; if (x > EXP_LIMIT_H) return Double.POSITIVE_INFINITY; if (x < EXP_LIMIT_L) return 0; // Argument reduction. double hi; double lo; int k; double t = abs(x); if (t > 0.5 * LN2) { if (t < 1.5 * LN2) { hi = t - LN2_H; lo = LN2_L; k = 1; } else { k = (int) (INV_LN2 * t + 0.5); hi = t - k * LN2_H; lo = k * LN2_L; } if (x < 0) { hi = -hi; lo = -lo; k = -k; } x = hi - lo; } else if (t < 1 / TWO_28) return 1; else lo = hi = k = 0; // Now x is in primary range. t = x * x; double c = x - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); if (k == 0) return 1 - (x * c / (c - 2) - x); double y = 1 - (lo - x * c / (2 - c) - hi); return scale(y, k); }
| 2,260
|
public static double exp(double x) { if (x != x) return x; if (x > EXP_LIMIT_H) return Double.POSITIVE_INFINITY; if (x < EXP_LIMIT_L) return 0; // Argument reduction. double hi; double lo; int k; double t = abs(x); if (t > 0.5 * LN2) { if (t < 1.5 * LN2) { hi = t - LN2_H; lo = LN2_L; k = 1; } else { k = (int) (INV_LN2 * t + 0.5); hi = t - k * LN2_H; lo = k * LN2_L; } if (x < 0) { hi = -hi; lo = -lo; k = -k; } x = hi - lo; } else if (t < 1 / TWO_28) return 1; else lo = hi = k = 0; // Now x is in primary range. t = x * x; double c = x - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); if (k == 0) return 1 - (x * c / (c - 2) - x); double y = 1 - (lo - x * c / (2 - c) - hi); return scale(y, k); }
|
public static double exp(double x) { if (x != x) return x; if (x > EXP_LIMIT_H) return Double.POSITIVE_INFINITY; if (x < EXP_LIMIT_L) return 0; // Argument reduction. double hi; double lo; int k; double t = abs(x); if (t > 0.5 * LN2) { if (t < 1.5 * LN2) { hi = t - LN2_H; lo = LN2_L; k = 1; } else { k = (int) (INV_LN2 * t + 0.5); hi = t - k * LN2_H; lo = k * LN2_L; } if (x < 0) { hi = -hi; lo = -lo; k = -k; } x = hi - lo; } else if (t < 1 / TWO_28) return 1; else lo = hi = k = 0; // Now x is in primary range. t = x * x; double c = x - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); if (k == 0) return 1 - (x * c / (c - 2) - x); double y = 1 - (lo - x * c / (2 - c) - hi); return scale(y, k); }
| 2,261
|
public static double exp(double x) { if (x != x) return x; if (x > EXP_LIMIT_H) return Double.POSITIVE_INFINITY; if (x < EXP_LIMIT_L) return 0; // Argument reduction. double hi; double lo; int k; double t = abs(x); if (t > 0.5 * LN2) { if (t < 1.5 * LN2) { hi = t - LN2_H; lo = LN2_L; k = 1; } else { k = (int) (INV_LN2 * t + 0.5); hi = t - k * LN2_H; lo = k * LN2_L; } if (x < 0) { hi = -hi; lo = -lo; k = -k; } x = hi - lo; } else if (t < 1 / TWO_28) return 1; else lo = hi = k = 0; // Now x is in primary range. t = x * x; double c = x - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); if (k == 0) return 1 - (x * c / (c - 2) - x); double y = 1 - (lo - x * c / (2 - c) - hi); return scale(y, k); }
|
public static double exp(double x) { if (x != x) return x; if (x > EXP_LIMIT_H) return Double.POSITIVE_INFINITY; if (x < EXP_LIMIT_L) return 0; // Argument reduction. double hi; double lo; int k; double t = abs(x); if (t > 0.5 * LN2) { if (t < 1.5 * LN2) { hi = t - LN2_H; lo = LN2_L; k = 1; } else { k = (int) (INV_LN2 * t + 0.5); hi = t - k * LN2_H; lo = k * LN2_L; } if (x < 0) { hi = -hi; lo = -lo; k = -k; } x = hi - lo; } else if (t < 1 / TWO_28) return 1; else lo = hi = k = 0; // Now x is in primary range. t = x * x; double c = x - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); if (k == 0) return 1 - (x * c / (c - 2) - x); double y = 1 - (lo - x * c / (2 - c) - hi); return scale(y, k); }
| 2,262
|
public static double exp(double x) { if (x != x) return x; if (x > EXP_LIMIT_H) return Double.POSITIVE_INFINITY; if (x < EXP_LIMIT_L) return 0; // Argument reduction. double hi; double lo; int k; double t = abs(x); if (t > 0.5 * LN2) { if (t < 1.5 * LN2) { hi = t - LN2_H; lo = LN2_L; k = 1; } else { k = (int) (INV_LN2 * t + 0.5); hi = t - k * LN2_H; lo = k * LN2_L; } if (x < 0) { hi = -hi; lo = -lo; k = -k; } x = hi - lo; } else if (t < 1 / TWO_28) return 1; else lo = hi = k = 0; // Now x is in primary range. t = x * x; double c = x - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); if (k == 0) return 1 - (x * c / (c - 2) - x); double y = 1 - (lo - x * c / (2 - c) - hi); return scale(y, k); }
|
public static double exp(double x) { if (x != x) return x; if (x > EXP_LIMIT_H) return Double.POSITIVE_INFINITY; if (x < EXP_LIMIT_L) return 0; // Argument reduction. double hi; double lo; int k; double t = abs(x); if (t > 0.5 * LN2) { if (t < 1.5 * LN2) { hi = t - LN2_H; lo = LN2_L; k = 1; } else { k = (int) (INV_LN2 * t + 0.5); hi = t - k * LN2_H; lo = k * LN2_L; } if (x < 0) { hi = -hi; lo = -lo; k = -k; } x = hi - lo; } else if (t < 1 / TWO_28) return 1; else lo = hi = k = 0; // Now x is in primary range. t = x * x; double c = x - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); if (k == 0) return 1 - (x * c / (c - 2) - x); double y = 1 - (lo - x * c / (2 - c) - hi); return scale(y, k); }
| 2,263
|
public static double exp(double x) { if (x != x) return x; if (x > EXP_LIMIT_H) return Double.POSITIVE_INFINITY; if (x < EXP_LIMIT_L) return 0; // Argument reduction. double hi; double lo; int k; double t = abs(x); if (t > 0.5 * LN2) { if (t < 1.5 * LN2) { hi = t - LN2_H; lo = LN2_L; k = 1; } else { k = (int) (INV_LN2 * t + 0.5); hi = t - k * LN2_H; lo = k * LN2_L; } if (x < 0) { hi = -hi; lo = -lo; k = -k; } x = hi - lo; } else if (t < 1 / TWO_28) return 1; else lo = hi = k = 0; // Now x is in primary range. t = x * x; double c = x - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); if (k == 0) return 1 - (x * c / (c - 2) - x); double y = 1 - (lo - x * c / (2 - c) - hi); return scale(y, k); }
|
public static double exp(double x) { if (x != x) return x; if (x > EXP_LIMIT_H) return Double.POSITIVE_INFINITY; if (x < EXP_LIMIT_L) return 0; // Argument reduction. double hi; double lo; int k; double t = abs(x); if (t > 0.5 * LN2) { if (t < 1.5 * LN2) { hi = t - LN2_H; lo = LN2_L; k = 1; } else { k = (int) (INV_LN2 * t + 0.5); hi = t - k * LN2_H; lo = k * LN2_L; } if (x < 0) { hi = -hi; lo = -lo; k = -k; } x = hi - lo; } else if (t < 1 / TWO_28) return 1; else lo = hi = k = 0; // Now x is in primary range. t = x * x; double c = x - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); if (k == 0) return 1 - (x * c / (c - 2) - x); double y = 1 - (lo - x * c / (2 - c) - hi); return scale(y, k); }
| 2,264
|
public static double floor(double a) { double x = abs(a); if (!(x < TWO_52) || (long) a == a) return a; // No fraction bits; includes NaN and infinity. if (x < 1) return a >= 0 ? 0 * a : -1; // Worry about signed zero. return a < 0 ? (long) a - 1.0 : (long) a; // Cast to long truncates. }
|
public static double floor(double a) { double x = abs(a); if (!(x < TWO_52) || (long) a == a) return a; // No fraction bits; includes NaN and infinity. if (x < 1) return a >= 0 ? 0 * a : -1; // Worry about signed zero. return a < 0 ? (long) a - 1.0 : (long) a; // Cast to long truncates. }
| 2,265
|
public static double floor(double a) { double x = abs(a); if (!(x < TWO_52) || (long) a == a) return a; // No fraction bits; includes NaN and infinity. if (x < 1) return a >= 0 ? 0 * a : -1; // Worry about signed zero. return a < 0 ? (long) a - 1.0 : (long) a; // Cast to long truncates. }
|
public static double floor(double a) { double x = abs(a); if (!(x < TWO_52) || (long) a == a) return a; // No fraction bits; includes NaN and infinity. if (x < 1) return a >= 0 ? 0 * a : -1; // Worry about signed zero. return a < 0 ? (long) a - 1.0 : (long) a; // Cast to long truncates. }
| 2,266
|
public static double log(double x) { if (x == 0) return Double.NEGATIVE_INFINITY; if (x < 0) return Double.NaN; if (!(x < Double.POSITIVE_INFINITY)) return x; // Normalize x. long bits = Double.doubleToLongBits(x); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { x *= TWO_54; bits = Double.doubleToLongBits(x); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. bits = (bits & 0x000fffffffffffffL) | 0x3ff0000000000000L; x = Double.longBitsToDouble(bits); if (x >= SQRT_2) { x *= 0.5; exp++; } x--; if (abs(x) < 1 / TWO_20) { if (x == 0) return exp * LN2_H + exp * LN2_L; double r = x * x * (0.5 - 1 / 3.0 * x); if (exp == 0) return x - r; return exp * LN2_H - ((r - exp * LN2_L) - x); } double s = x / (2 + x); double z = s * s; double w = z * z; double t1 = w * (LG2 + w * (LG4 + w * LG6)); double t2 = z * (LG1 + w * (LG3 + w * (LG5 + w * LG7))); double r = t2 + t1; if (bits >= 0x3ff6174a00000000L && bits < 0x3ff6b85200000000L) { double h = 0.5 * x * x; // Need more accuracy for x near sqrt(2). if (exp == 0) return x - (h - s * (h + r)); return exp * LN2_H - ((h - (s * (h + r) + exp * LN2_L)) - x); } if (exp == 0) return x - s * (x - r); return exp * LN2_H - ((s * (x - r) - exp * LN2_L) - x); }
|
public static double log(double x) { if (x == 0) return Double.NEGATIVE_INFINITY; if (x < 0) return Double.NaN; if (!(x < Double.POSITIVE_INFINITY)) return x; // Normalize x. long bits = Double.doubleToLongBits(x); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { x *= TWO_54; bits = Double.doubleToLongBits(x); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. bits = (bits & 0x000fffffffffffffL) | 0x3ff0000000000000L; x = Double.longBitsToDouble(bits); if (x >= SQRT_2) { x *= 0.5; exp++; } x--; if (abs(x) < 1 / TWO_20) { if (x == 0) return exp * LN2_H + exp * LN2_L; double r = x * x * (0.5 - 1 / 3.0 * x); if (exp == 0) return x - r; return exp * LN2_H - ((r - exp * LN2_L) - x); } double s = x / (2 + x); double z = s * s; double w = z * z; double t1 = w * (LG2 + w * (LG4 + w * LG6)); double t2 = z * (LG1 + w * (LG3 + w * (LG5 + w * LG7))); double r = t2 + t1; if (bits >= 0x3ff6174a00000000L && bits < 0x3ff6b85200000000L) { double h = 0.5 * x * x; // Need more accuracy for x near sqrt(2). if (exp == 0) return x - (h - s * (h + r)); return exp * LN2_H - ((h - (s * (h + r) + exp * LN2_L)) - x); } if (exp == 0) return x - s * (x - r); return exp * LN2_H - ((s * (x - r) - exp * LN2_L) - x); }
| 2,267
|
public static double log(double x) { if (x == 0) return Double.NEGATIVE_INFINITY; if (x < 0) return Double.NaN; if (!(x < Double.POSITIVE_INFINITY)) return x; // Normalize x. long bits = Double.doubleToLongBits(x); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { x *= TWO_54; bits = Double.doubleToLongBits(x); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. bits = (bits & 0x000fffffffffffffL) | 0x3ff0000000000000L; x = Double.longBitsToDouble(bits); if (x >= SQRT_2) { x *= 0.5; exp++; } x--; if (abs(x) < 1 / TWO_20) { if (x == 0) return exp * LN2_H + exp * LN2_L; double r = x * x * (0.5 - 1 / 3.0 * x); if (exp == 0) return x - r; return exp * LN2_H - ((r - exp * LN2_L) - x); } double s = x / (2 + x); double z = s * s; double w = z * z; double t1 = w * (LG2 + w * (LG4 + w * LG6)); double t2 = z * (LG1 + w * (LG3 + w * (LG5 + w * LG7))); double r = t2 + t1; if (bits >= 0x3ff6174a00000000L && bits < 0x3ff6b85200000000L) { double h = 0.5 * x * x; // Need more accuracy for x near sqrt(2). if (exp == 0) return x - (h - s * (h + r)); return exp * LN2_H - ((h - (s * (h + r) + exp * LN2_L)) - x); } if (exp == 0) return x - s * (x - r); return exp * LN2_H - ((s * (x - r) - exp * LN2_L) - x); }
|
public static double log(double x) { if (x == 0) return Double.NEGATIVE_INFINITY; if (x < 0) return Double.NaN; if (!(x < Double.POSITIVE_INFINITY)) return x; // Normalize x. long bits = Double.doubleToLongBits(x); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { x *= TWO_54; bits = Double.doubleToLongBits(x); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. bits = (bits & 0x000fffffffffffffL) | 0x3ff0000000000000L; x = Double.longBitsToDouble(bits); if (x >= SQRT_2) { x *= 0.5; exp++; } x--; if (abs(x) < 1 / TWO_20) { if (x == 0) return exp * LN2_H + exp * LN2_L; double r = x * x * (0.5 - 1 / 3.0 * x); if (exp == 0) return x - r; return exp * LN2_H - ((r - exp * LN2_L) - x); } double s = x / (2 + x); double z = s * s; double w = z * z; double t1 = w * (LG2 + w * (LG4 + w * LG6)); double t2 = z * (LG1 + w * (LG3 + w * (LG5 + w * LG7))); double r = t2 + t1; if (bits >= 0x3ff6174a00000000L && bits < 0x3ff6b85200000000L) { double h = 0.5 * x * x; // Need more accuracy for x near sqrt(2). if (exp == 0) return x - (h - s * (h + r)); return exp * LN2_H - ((h - (s * (h + r) + exp * LN2_L)) - x); } if (exp == 0) return x - s * (x - r); return exp * LN2_H - ((s * (x - r) - exp * LN2_L) - x); }
| 2,268
|
public static double log(double x) { if (x == 0) return Double.NEGATIVE_INFINITY; if (x < 0) return Double.NaN; if (!(x < Double.POSITIVE_INFINITY)) return x; // Normalize x. long bits = Double.doubleToLongBits(x); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { x *= TWO_54; bits = Double.doubleToLongBits(x); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. bits = (bits & 0x000fffffffffffffL) | 0x3ff0000000000000L; x = Double.longBitsToDouble(bits); if (x >= SQRT_2) { x *= 0.5; exp++; } x--; if (abs(x) < 1 / TWO_20) { if (x == 0) return exp * LN2_H + exp * LN2_L; double r = x * x * (0.5 - 1 / 3.0 * x); if (exp == 0) return x - r; return exp * LN2_H - ((r - exp * LN2_L) - x); } double s = x / (2 + x); double z = s * s; double w = z * z; double t1 = w * (LG2 + w * (LG4 + w * LG6)); double t2 = z * (LG1 + w * (LG3 + w * (LG5 + w * LG7))); double r = t2 + t1; if (bits >= 0x3ff6174a00000000L && bits < 0x3ff6b85200000000L) { double h = 0.5 * x * x; // Need more accuracy for x near sqrt(2). if (exp == 0) return x - (h - s * (h + r)); return exp * LN2_H - ((h - (s * (h + r) + exp * LN2_L)) - x); } if (exp == 0) return x - s * (x - r); return exp * LN2_H - ((s * (x - r) - exp * LN2_L) - x); }
|
public static double log(double x) { if (x == 0) return Double.NEGATIVE_INFINITY; if (x < 0) return Double.NaN; if (!(x < Double.POSITIVE_INFINITY)) return x; // Normalize x. long bits = Double.doubleToLongBits(x); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { x *= TWO_54; bits = Double.doubleToLongBits(x); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. bits = (bits & 0x000fffffffffffffL) | 0x3ff0000000000000L; x = Double.longBitsToDouble(bits); if (x >= SQRT_2) { x *= 0.5; exp++; } x--; if (abs(x) < 1 / TWO_20) { if (x == 0) return exp * LN2_H + exp * LN2_L; double r = x * x * (0.5 - 1 / 3.0 * x); if (exp == 0) return x - r; return exp * LN2_H - ((r - exp * LN2_L) - x); } double s = x / (2 + x); double z = s * s; double w = z * z; double t1 = w * (LG2 + w * (LG4 + w * LG6)); double t2 = z * (LG1 + w * (LG3 + w * (LG5 + w * LG7))); double r = t2 + t1; if (bits >= 0x3ff6174a00000000L && bits < 0x3ff6b85200000000L) { double h = 0.5 * x * x; // Need more accuracy for x near sqrt(2). if (exp == 0) return x - (h - s * (h + r)); return exp * LN2_H - ((h - (s * (h + r) + exp * LN2_L)) - x); } if (exp == 0) return x - s * (x - r); return exp * LN2_H - ((s * (x - r) - exp * LN2_L) - x); }
| 2,269
|
public static double log(double x) { if (x == 0) return Double.NEGATIVE_INFINITY; if (x < 0) return Double.NaN; if (!(x < Double.POSITIVE_INFINITY)) return x; // Normalize x. long bits = Double.doubleToLongBits(x); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { x *= TWO_54; bits = Double.doubleToLongBits(x); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. bits = (bits & 0x000fffffffffffffL) | 0x3ff0000000000000L; x = Double.longBitsToDouble(bits); if (x >= SQRT_2) { x *= 0.5; exp++; } x--; if (abs(x) < 1 / TWO_20) { if (x == 0) return exp * LN2_H + exp * LN2_L; double r = x * x * (0.5 - 1 / 3.0 * x); if (exp == 0) return x - r; return exp * LN2_H - ((r - exp * LN2_L) - x); } double s = x / (2 + x); double z = s * s; double w = z * z; double t1 = w * (LG2 + w * (LG4 + w * LG6)); double t2 = z * (LG1 + w * (LG3 + w * (LG5 + w * LG7))); double r = t2 + t1; if (bits >= 0x3ff6174a00000000L && bits < 0x3ff6b85200000000L) { double h = 0.5 * x * x; // Need more accuracy for x near sqrt(2). if (exp == 0) return x - (h - s * (h + r)); return exp * LN2_H - ((h - (s * (h + r) + exp * LN2_L)) - x); } if (exp == 0) return x - s * (x - r); return exp * LN2_H - ((s * (x - r) - exp * LN2_L) - x); }
|
public static double log(double x) { if (x == 0) return Double.NEGATIVE_INFINITY; if (x < 0) return Double.NaN; if (!(x < Double.POSITIVE_INFINITY)) return x; // Normalize x. long bits = Double.doubleToLongBits(x); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { x *= TWO_54; bits = Double.doubleToLongBits(x); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. bits = (bits & 0x000fffffffffffffL) | 0x3ff0000000000000L; x = Double.longBitsToDouble(bits); if (x >= SQRT_2) { x *= 0.5; exp++; } x--; if (abs(x) < 1 / TWO_20) { if (x == 0) return exp * LN2_H + exp * LN2_L; double r = x * x * (0.5 - 1 / 3.0 * x); if (exp == 0) return x - r; return exp * LN2_H - ((r - exp * LN2_L) - x); } double s = x / (2 + x); double z = s * s; double w = z * z; double t1 = w * (LG2 + w * (LG4 + w * LG6)); double t2 = z * (LG1 + w * (LG3 + w * (LG5 + w * LG7))); double r = t2 + t1; if (bits >= 0x3ff6174a00000000L && bits < 0x3ff6b85200000000L) { double h = 0.5 * x * x; // Need more accuracy for x near sqrt(2). if (exp == 0) return x - (h - s * (h + r)); return exp * LN2_H - ((h - (s * (h + r) + exp * LN2_L)) - x); } if (exp == 0) return x - s * (x - r); return exp * LN2_H - ((s * (x - r) - exp * LN2_L) - x); }
| 2,270
|
public static double log(double x) { if (x == 0) return Double.NEGATIVE_INFINITY; if (x < 0) return Double.NaN; if (!(x < Double.POSITIVE_INFINITY)) return x; // Normalize x. long bits = Double.doubleToLongBits(x); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { x *= TWO_54; bits = Double.doubleToLongBits(x); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. bits = (bits & 0x000fffffffffffffL) | 0x3ff0000000000000L; x = Double.longBitsToDouble(bits); if (x >= SQRT_2) { x *= 0.5; exp++; } x--; if (abs(x) < 1 / TWO_20) { if (x == 0) return exp * LN2_H + exp * LN2_L; double r = x * x * (0.5 - 1 / 3.0 * x); if (exp == 0) return x - r; return exp * LN2_H - ((r - exp * LN2_L) - x); } double s = x / (2 + x); double z = s * s; double w = z * z; double t1 = w * (LG2 + w * (LG4 + w * LG6)); double t2 = z * (LG1 + w * (LG3 + w * (LG5 + w * LG7))); double r = t2 + t1; if (bits >= 0x3ff6174a00000000L && bits < 0x3ff6b85200000000L) { double h = 0.5 * x * x; // Need more accuracy for x near sqrt(2). if (exp == 0) return x - (h - s * (h + r)); return exp * LN2_H - ((h - (s * (h + r) + exp * LN2_L)) - x); } if (exp == 0) return x - s * (x - r); return exp * LN2_H - ((s * (x - r) - exp * LN2_L) - x); }
|
public static double log(double x) { if (x == 0) return Double.NEGATIVE_INFINITY; if (x < 0) return Double.NaN; if (!(x < Double.POSITIVE_INFINITY)) return x; // Normalize x. long bits = Double.doubleToLongBits(x); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { x *= TWO_54; bits = Double.doubleToLongBits(x); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. bits = (bits & 0x000fffffffffffffL) | 0x3ff0000000000000L; x = Double.longBitsToDouble(bits); if (x >= SQRT_2) { x *= 0.5; exp++; } x--; if (abs(x) < 1 / TWO_20) { if (x == 0) return exp * LN2_H + exp * LN2_L; double r = x * x * (0.5 - 1 / 3.0 * x); if (exp == 0) return x - r; return exp * LN2_H - ((r - exp * LN2_L) - x); } double s = x / (2 + x); double z = s * s; double w = z * z; double t1 = w * (LG2 + w * (LG4 + w * LG6)); double t2 = z * (LG1 + w * (LG3 + w * (LG5 + w * LG7))); double r = t2 + t1; if (bits >= 0x3ff6174a00000000L && bits < 0x3ff6b85200000000L) { double h = 0.5 * x * x; // Need more accuracy for x near sqrt(2). if (exp == 0) return x - (h - s * (h + r)); return exp * LN2_H - ((h - (s * (h + r) + exp * LN2_L)) - x); } if (exp == 0) return x - s * (x - r); return exp * LN2_H - ((s * (x - r) - exp * LN2_L) - x); }
| 2,271
|
public static int max(int a, int b) { return (a > b) ? a : b; }
|
public static int max(int a, int b) { return (a > b) ? a : b; }
| 2,272
|
public static int min(int a, int b) { return (a < b) ? a : b; }
|
public static int min(int a, int b) { return (a < b) ? a : b; }
| 2,273
|
public static double pow(double x, double y) { // Special cases first. if (y == 0) return 1; if (y == 1) return x; if (y == -1) return 1 / x; if (x != x || y != y) return Double.NaN; // When x < 0, yisint tells if y is not an integer (0), even(1), // or odd (2). int yisint = 0; if (x < 0 && floor(y) == y) yisint = (y % 2 == 0) ? 2 : 1; double ax = abs(x); double ay = abs(y); // More special cases, of y. if (ay == Double.POSITIVE_INFINITY) { if (ax == 1) return Double.NaN; if (ax > 1) return y > 0 ? y : 0; return y < 0 ? -y : 0; } if (y == 2) return x * x; if (y == 0.5) return sqrt(x); // More special cases, of x. if (x == 0 || ax == Double.POSITIVE_INFINITY || ax == 1) { if (y < 0) ax = 1 / ax; if (x < 0) { if (x == -1 && yisint == 0) ax = Double.NaN; else if (yisint == 1) ax = -ax; } return ax; } if (x < 0 && yisint == 0) return Double.NaN; // Now we can start! double t; double t1; double t2; double u; double v; double w; if (ay > TWO_31) { if (ay > TWO_64) // Automatic over/underflow. return ((ax < 1) ? y < 0 : y > 0) ? Double.POSITIVE_INFINITY : 0; // Over/underflow if x is not close to one. if (ax < 0.9999995231628418) return y < 0 ? Double.POSITIVE_INFINITY : 0; if (ax >= 1.0000009536743164) return y > 0 ? Double.POSITIVE_INFINITY : 0; // Now |1-x| is <= 2**-20, sufficient to compute // log(x) by x-x^2/2+x^3/3-x^4/4. t = x - 1; w = t * t * (0.5 - t * (1 / 3.0 - t * 0.25)); u = INV_LN2_H * t; v = t * INV_LN2_L - w * INV_LN2; t1 = (float) (u + v); t2 = v - (t1 - u); } else { long bits = Double.doubleToLongBits(ax); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { ax *= TWO_54; bits = Double.doubleToLongBits(ax); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. ax = Double.longBitsToDouble((bits & 0x000fffffffffffffL) | 0x3ff0000000000000L); boolean k; if (ax < SQRT_1_5) // |x|<sqrt(3/2). k = false; else if (ax < SQRT_3) // |x|<sqrt(3). k = true; else { k = false; ax *= 0.5; exp++; } // Compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5). u = ax - (k ? 1.5 : 1); v = 1 / (ax + (k ? 1.5 : 1)); double s = u * v; double s_h = (float) s; double t_h = (float) (ax + (k ? 1.5 : 1)); double t_l = ax - (t_h - (k ? 1.5 : 1)); double s_l = v * ((u - s_h * t_h) - s_h * t_l); // Compute log(ax). double s2 = s * s; double r = s_l * (s_h + s) + s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6))))); s2 = s_h * s_h; t_h = (float) (3.0 + s2 + r); t_l = r - (t_h - 3.0 - s2); // u+v = s*(1+...). u = s_h * t_h; v = s_l * t_h + t_l * s; // 2/(3log2)*(s+...). double p_h = (float) (u + v); double p_l = v - (p_h - u); double z_h = CP_H * p_h; double z_l = CP_L * p_h + p_l * CP + (k ? DP_L : 0); // log2(ax) = (s+..)*2/(3*log2) = exp + dp_h + z_h + z_l. t = exp; t1 = (float) (z_h + z_l + (k ? DP_H : 0) + t); t2 = z_l - (t1 - t - (k ? DP_H : 0) - z_h); } // Split up y into y1+y2 and compute (y1+y2)*(t1+t2). boolean negative = x < 0 && yisint == 1; double y1 = (float) y; double p_l = (y - y1) * t1 + y * t2; double p_h = y1 * t1; double z = p_l + p_h; if (z >= 1024) // Detect overflow. { if (z > 1024 || p_l + OVT > z - p_h) return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } else if (z <= -1075) // Detect underflow. { if (z < -1075 || p_l <= z - p_h) return negative ? -0.0 : 0; } // Compute 2**(p_h+p_l). int n = round((float) z); p_h -= n; t = (float) (p_l + p_h); u = t * LN2_H; v = (p_l - (t - p_h)) * LN2 + t * LN2_L; z = u + v; w = v - (z - u); t = z * z; t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); double r = (z * t1) / (t1 - 2) - (w + z * w); z = scale(1 - (r - z), n); return negative ? -z : z; }
|
public static double pow(double x, double y) { // Special cases first. if (y == 0) return 1; if (y == 1) return x; if (y == -1) return 1 / x; if (x != x || y != y) return Double.NaN; // When x < 0, yisint tells if y is not an integer (0), even(1), // or odd (2). int yisint = 0; if (x < 0 && floor(y) == y) yisint = (y % 2 == 0) ? 2 : 1; double ax = abs(x); double ay = abs(y); // More special cases, of y. if (ay == Double.POSITIVE_INFINITY) { if (ax == 1) return Double.NaN; if (ax > 1) return y > 0 ? y : 0; return y < 0 ? -y : 0; } if (y == 2) return x * x; if (y == 0.5) return sqrt(x); // More special cases, of x. if (x == 0 || ax == Double.POSITIVE_INFINITY || ax == 1) { if (y < 0) ax = 1 / ax; if (x < 0) { if (x == -1 && yisint == 0) ax = Double.NaN; else if (yisint == 1) ax = -ax; } return ax; } if (x < 0 && yisint == 0) return Double.NaN; // Now we can start! double t; double t1; double t2; double u; double v; double w; if (ay > TWO_31) { if (ay > TWO_64) // Automatic over/underflow. return ((ax < 1) ? y < 0 : y > 0) ? Double.POSITIVE_INFINITY : 0; // Over/underflow if x is not close to one. if (ax < 0.9999995231628418) return y < 0 ? Double.POSITIVE_INFINITY : 0; if (ax >= 1.0000009536743164) return y > 0 ? Double.POSITIVE_INFINITY : 0; // Now |1-x| is <= 2**-20, sufficient to compute // log(x) by x-x^2/2+x^3/3-x^4/4. t = x - 1; w = t * t * (0.5 - t * (1 / 3.0 - t * 0.25)); u = INV_LN2_H * t; v = t * INV_LN2_L - w * INV_LN2; t1 = (float) (u + v); t2 = v - (t1 - u); } else { long bits = Double.doubleToLongBits(ax); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { ax *= TWO_54; bits = Double.doubleToLongBits(ax); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. ax = Double.longBitsToDouble((bits & 0x000fffffffffffffL) | 0x3ff0000000000000L); boolean k; if (ax < SQRT_1_5) // |x|<sqrt(3/2). k = false; else if (ax < SQRT_3) // |x|<sqrt(3). k = true; else { k = false; ax *= 0.5; exp++; } // Compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5). u = ax - (k ? 1.5 : 1); v = 1 / (ax + (k ? 1.5 : 1)); double s = u * v; double s_h = (float) s; double t_h = (float) (ax + (k ? 1.5 : 1)); double t_l = ax - (t_h - (k ? 1.5 : 1)); double s_l = v * ((u - s_h * t_h) - s_h * t_l); // Compute log(ax). double s2 = s * s; double r = s_l * (s_h + s) + s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6))))); s2 = s_h * s_h; t_h = (float) (3.0 + s2 + r); t_l = r - (t_h - 3.0 - s2); // u+v = s*(1+...). u = s_h * t_h; v = s_l * t_h + t_l * s; // 2/(3log2)*(s+...). double p_h = (float) (u + v); double p_l = v - (p_h - u); double z_h = CP_H * p_h; double z_l = CP_L * p_h + p_l * CP + (k ? DP_L : 0); // log2(ax) = (s+..)*2/(3*log2) = exp + dp_h + z_h + z_l. t = exp; t1 = (float) (z_h + z_l + (k ? DP_H : 0) + t); t2 = z_l - (t1 - t - (k ? DP_H : 0) - z_h); } // Split up y into y1+y2 and compute (y1+y2)*(t1+t2). boolean negative = x < 0 && yisint == 1; double y1 = (float) y; double p_l = (y - y1) * t1 + y * t2; double p_h = y1 * t1; double z = p_l + p_h; if (z >= 1024) // Detect overflow. { if (z > 1024 || p_l + OVT > z - p_h) return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } else if (z <= -1075) // Detect underflow. { if (z < -1075 || p_l <= z - p_h) return negative ? -0.0 : 0; } // Compute 2**(p_h+p_l). int n = round((float) z); p_h -= n; t = (float) (p_l + p_h); u = t * LN2_H; v = (p_l - (t - p_h)) * LN2 + t * LN2_L; z = u + v; w = v - (z - u); t = z * z; t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); double r = (z * t1) / (t1 - 2) - (w + z * w); z = scale(1 - (r - z), n); return negative ? -z : z; }
| 2,274
|
public static double pow(double x, double y) { // Special cases first. if (y == 0) return 1; if (y == 1) return x; if (y == -1) return 1 / x; if (x != x || y != y) return Double.NaN; // When x < 0, yisint tells if y is not an integer (0), even(1), // or odd (2). int yisint = 0; if (x < 0 && floor(y) == y) yisint = (y % 2 == 0) ? 2 : 1; double ax = abs(x); double ay = abs(y); // More special cases, of y. if (ay == Double.POSITIVE_INFINITY) { if (ax == 1) return Double.NaN; if (ax > 1) return y > 0 ? y : 0; return y < 0 ? -y : 0; } if (y == 2) return x * x; if (y == 0.5) return sqrt(x); // More special cases, of x. if (x == 0 || ax == Double.POSITIVE_INFINITY || ax == 1) { if (y < 0) ax = 1 / ax; if (x < 0) { if (x == -1 && yisint == 0) ax = Double.NaN; else if (yisint == 1) ax = -ax; } return ax; } if (x < 0 && yisint == 0) return Double.NaN; // Now we can start! double t; double t1; double t2; double u; double v; double w; if (ay > TWO_31) { if (ay > TWO_64) // Automatic over/underflow. return ((ax < 1) ? y < 0 : y > 0) ? Double.POSITIVE_INFINITY : 0; // Over/underflow if x is not close to one. if (ax < 0.9999995231628418) return y < 0 ? Double.POSITIVE_INFINITY : 0; if (ax >= 1.0000009536743164) return y > 0 ? Double.POSITIVE_INFINITY : 0; // Now |1-x| is <= 2**-20, sufficient to compute // log(x) by x-x^2/2+x^3/3-x^4/4. t = x - 1; w = t * t * (0.5 - t * (1 / 3.0 - t * 0.25)); u = INV_LN2_H * t; v = t * INV_LN2_L - w * INV_LN2; t1 = (float) (u + v); t2 = v - (t1 - u); } else { long bits = Double.doubleToLongBits(ax); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { ax *= TWO_54; bits = Double.doubleToLongBits(ax); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. ax = Double.longBitsToDouble((bits & 0x000fffffffffffffL) | 0x3ff0000000000000L); boolean k; if (ax < SQRT_1_5) // |x|<sqrt(3/2). k = false; else if (ax < SQRT_3) // |x|<sqrt(3). k = true; else { k = false; ax *= 0.5; exp++; } // Compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5). u = ax - (k ? 1.5 : 1); v = 1 / (ax + (k ? 1.5 : 1)); double s = u * v; double s_h = (float) s; double t_h = (float) (ax + (k ? 1.5 : 1)); double t_l = ax - (t_h - (k ? 1.5 : 1)); double s_l = v * ((u - s_h * t_h) - s_h * t_l); // Compute log(ax). double s2 = s * s; double r = s_l * (s_h + s) + s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6))))); s2 = s_h * s_h; t_h = (float) (3.0 + s2 + r); t_l = r - (t_h - 3.0 - s2); // u+v = s*(1+...). u = s_h * t_h; v = s_l * t_h + t_l * s; // 2/(3log2)*(s+...). double p_h = (float) (u + v); double p_l = v - (p_h - u); double z_h = CP_H * p_h; double z_l = CP_L * p_h + p_l * CP + (k ? DP_L : 0); // log2(ax) = (s+..)*2/(3*log2) = exp + dp_h + z_h + z_l. t = exp; t1 = (float) (z_h + z_l + (k ? DP_H : 0) + t); t2 = z_l - (t1 - t - (k ? DP_H : 0) - z_h); } // Split up y into y1+y2 and compute (y1+y2)*(t1+t2). boolean negative = x < 0 && yisint == 1; double y1 = (float) y; double p_l = (y - y1) * t1 + y * t2; double p_h = y1 * t1; double z = p_l + p_h; if (z >= 1024) // Detect overflow. { if (z > 1024 || p_l + OVT > z - p_h) return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } else if (z <= -1075) // Detect underflow. { if (z < -1075 || p_l <= z - p_h) return negative ? -0.0 : 0; } // Compute 2**(p_h+p_l). int n = round((float) z); p_h -= n; t = (float) (p_l + p_h); u = t * LN2_H; v = (p_l - (t - p_h)) * LN2 + t * LN2_L; z = u + v; w = v - (z - u); t = z * z; t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); double r = (z * t1) / (t1 - 2) - (w + z * w); z = scale(1 - (r - z), n); return negative ? -z : z; }
|
public static double pow(double x, double y) { // Special cases first. if (y == 0) return 1; if (y == 1) return x; if (y == -1) return 1 / x; if (x != x || y != y) return Double.NaN; // When x < 0, yisint tells if y is not an integer (0), even(1), // or odd (2). int yisint = 0; if (x < 0 && floor(y) == y) yisint = (y % 2 == 0) ? 2 : 1; double ax = abs(x); double ay = abs(y); // More special cases, of y. if (ay == Double.POSITIVE_INFINITY) { if (ax == 1) return Double.NaN; if (ax > 1) return y > 0 ? y : 0; return y < 0 ? -y : 0; } if (y == 2) return x * x; if (y == 0.5) return sqrt(x); // More special cases, of x. if (x == 0 || ax == Double.POSITIVE_INFINITY || ax == 1) { if (y < 0) ax = 1 / ax; if (x < 0) { if (x == -1 && yisint == 0) ax = Double.NaN; else if (yisint == 1) ax = -ax; } return ax; } if (x < 0 && yisint == 0) return Double.NaN; // Now we can start! double t; double t1; double t2; double u; double v; double w; if (ay > TWO_31) { if (ay > TWO_64) // Automatic over/underflow. return ((ax < 1) ? y < 0 : y > 0) ? Double.POSITIVE_INFINITY : 0; // Over/underflow if x is not close to one. if (ax < 0.9999995231628418) return y < 0 ? Double.POSITIVE_INFINITY : 0; if (ax >= 1.0000009536743164) return y > 0 ? Double.POSITIVE_INFINITY : 0; // Now |1-x| is <= 2**-20, sufficient to compute // log(x) by x-x^2/2+x^3/3-x^4/4. t = x - 1; w = t * t * (0.5 - t * (1 / 3.0 - t * 0.25)); u = INV_LN2_H * t; v = t * INV_LN2_L - w * INV_LN2; t1 = (float) (u + v); t2 = v - (t1 - u); } else { long bits = Double.doubleToLongBits(ax); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { ax *= TWO_54; bits = Double.doubleToLongBits(ax); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. ax = Double.longBitsToDouble((bits & 0x000fffffffffffffL) | 0x3ff0000000000000L); boolean k; if (ax < SQRT_1_5) // |x|<sqrt(3/2). k = false; else if (ax < SQRT_3) // |x|<sqrt(3). k = true; else { k = false; ax *= 0.5; exp++; } // Compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5). u = ax - (k ? 1.5 : 1); v = 1 / (ax + (k ? 1.5 : 1)); double s = u * v; double s_h = (float) s; double t_h = (float) (ax + (k ? 1.5 : 1)); double t_l = ax - (t_h - (k ? 1.5 : 1)); double s_l = v * ((u - s_h * t_h) - s_h * t_l); // Compute log(ax). double s2 = s * s; double r = s_l * (s_h + s) + s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6))))); s2 = s_h * s_h; t_h = (float) (3.0 + s2 + r); t_l = r - (t_h - 3.0 - s2); // u+v = s*(1+...). u = s_h * t_h; v = s_l * t_h + t_l * s; // 2/(3log2)*(s+...). double p_h = (float) (u + v); double p_l = v - (p_h - u); double z_h = CP_H * p_h; double z_l = CP_L * p_h + p_l * CP + (k ? DP_L : 0); // log2(ax) = (s+..)*2/(3*log2) = exp + dp_h + z_h + z_l. t = exp; t1 = (float) (z_h + z_l + (k ? DP_H : 0) + t); t2 = z_l - (t1 - t - (k ? DP_H : 0) - z_h); } // Split up y into y1+y2 and compute (y1+y2)*(t1+t2). boolean negative = x < 0 && yisint == 1; double y1 = (float) y; double p_l = (y - y1) * t1 + y * t2; double p_h = y1 * t1; double z = p_l + p_h; if (z >= 1024) // Detect overflow. { if (z > 1024 || p_l + OVT > z - p_h) return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } else if (z <= -1075) // Detect underflow. { if (z < -1075 || p_l <= z - p_h) return negative ? -0.0 : 0; } // Compute 2**(p_h+p_l). int n = round((float) z); p_h -= n; t = (float) (p_l + p_h); u = t * LN2_H; v = (p_l - (t - p_h)) * LN2 + t * LN2_L; z = u + v; w = v - (z - u); t = z * z; t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); double r = (z * t1) / (t1 - 2) - (w + z * w); z = scale(1 - (r - z), n); return negative ? -z : z; }
| 2,275
|
public static double pow(double x, double y) { // Special cases first. if (y == 0) return 1; if (y == 1) return x; if (y == -1) return 1 / x; if (x != x || y != y) return Double.NaN; // When x < 0, yisint tells if y is not an integer (0), even(1), // or odd (2). int yisint = 0; if (x < 0 && floor(y) == y) yisint = (y % 2 == 0) ? 2 : 1; double ax = abs(x); double ay = abs(y); // More special cases, of y. if (ay == Double.POSITIVE_INFINITY) { if (ax == 1) return Double.NaN; if (ax > 1) return y > 0 ? y : 0; return y < 0 ? -y : 0; } if (y == 2) return x * x; if (y == 0.5) return sqrt(x); // More special cases, of x. if (x == 0 || ax == Double.POSITIVE_INFINITY || ax == 1) { if (y < 0) ax = 1 / ax; if (x < 0) { if (x == -1 && yisint == 0) ax = Double.NaN; else if (yisint == 1) ax = -ax; } return ax; } if (x < 0 && yisint == 0) return Double.NaN; // Now we can start! double t; double t1; double t2; double u; double v; double w; if (ay > TWO_31) { if (ay > TWO_64) // Automatic over/underflow. return ((ax < 1) ? y < 0 : y > 0) ? Double.POSITIVE_INFINITY : 0; // Over/underflow if x is not close to one. if (ax < 0.9999995231628418) return y < 0 ? Double.POSITIVE_INFINITY : 0; if (ax >= 1.0000009536743164) return y > 0 ? Double.POSITIVE_INFINITY : 0; // Now |1-x| is <= 2**-20, sufficient to compute // log(x) by x-x^2/2+x^3/3-x^4/4. t = x - 1; w = t * t * (0.5 - t * (1 / 3.0 - t * 0.25)); u = INV_LN2_H * t; v = t * INV_LN2_L - w * INV_LN2; t1 = (float) (u + v); t2 = v - (t1 - u); } else { long bits = Double.doubleToLongBits(ax); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { ax *= TWO_54; bits = Double.doubleToLongBits(ax); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. ax = Double.longBitsToDouble((bits & 0x000fffffffffffffL) | 0x3ff0000000000000L); boolean k; if (ax < SQRT_1_5) // |x|<sqrt(3/2). k = false; else if (ax < SQRT_3) // |x|<sqrt(3). k = true; else { k = false; ax *= 0.5; exp++; } // Compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5). u = ax - (k ? 1.5 : 1); v = 1 / (ax + (k ? 1.5 : 1)); double s = u * v; double s_h = (float) s; double t_h = (float) (ax + (k ? 1.5 : 1)); double t_l = ax - (t_h - (k ? 1.5 : 1)); double s_l = v * ((u - s_h * t_h) - s_h * t_l); // Compute log(ax). double s2 = s * s; double r = s_l * (s_h + s) + s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6))))); s2 = s_h * s_h; t_h = (float) (3.0 + s2 + r); t_l = r - (t_h - 3.0 - s2); // u+v = s*(1+...). u = s_h * t_h; v = s_l * t_h + t_l * s; // 2/(3log2)*(s+...). double p_h = (float) (u + v); double p_l = v - (p_h - u); double z_h = CP_H * p_h; double z_l = CP_L * p_h + p_l * CP + (k ? DP_L : 0); // log2(ax) = (s+..)*2/(3*log2) = exp + dp_h + z_h + z_l. t = exp; t1 = (float) (z_h + z_l + (k ? DP_H : 0) + t); t2 = z_l - (t1 - t - (k ? DP_H : 0) - z_h); } // Split up y into y1+y2 and compute (y1+y2)*(t1+t2). boolean negative = x < 0 && yisint == 1; double y1 = (float) y; double p_l = (y - y1) * t1 + y * t2; double p_h = y1 * t1; double z = p_l + p_h; if (z >= 1024) // Detect overflow. { if (z > 1024 || p_l + OVT > z - p_h) return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } else if (z <= -1075) // Detect underflow. { if (z < -1075 || p_l <= z - p_h) return negative ? -0.0 : 0; } // Compute 2**(p_h+p_l). int n = round((float) z); p_h -= n; t = (float) (p_l + p_h); u = t * LN2_H; v = (p_l - (t - p_h)) * LN2 + t * LN2_L; z = u + v; w = v - (z - u); t = z * z; t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); double r = (z * t1) / (t1 - 2) - (w + z * w); z = scale(1 - (r - z), n); return negative ? -z : z; }
|
public static double pow(double x, double y) { // Special cases first. if (y == 0) return 1; if (y == 1) return x; if (y == -1) return 1 / x; if (x != x || y != y) return Double.NaN; // When x < 0, yisint tells if y is not an integer (0), even(1), // or odd (2). int yisint = 0; if (x < 0 && floor(y) == y) yisint = (y % 2 == 0) ? 2 : 1; double ax = abs(x); double ay = abs(y); // More special cases, of y. if (ay == Double.POSITIVE_INFINITY) { if (ax == 1) return Double.NaN; if (ax > 1) return y > 0 ? y : 0; return y < 0 ? -y : 0; } if (y == 2) return x * x; if (y == 0.5) return sqrt(x); // More special cases, of x. if (x == 0 || ax == Double.POSITIVE_INFINITY || ax == 1) { if (y < 0) ax = 1 / ax; if (x < 0) { if (x == -1 && yisint == 0) ax = Double.NaN; else if (yisint == 1) ax = -ax; } return ax; } if (x < 0 && yisint == 0) return Double.NaN; // Now we can start! double t; double t1; double t2; double u; double v; double w; if (ay > TWO_31) { if (ay > TWO_64) // Automatic over/underflow. return ((ax < 1) ? y < 0 : y > 0) ? Double.POSITIVE_INFINITY : 0; // Over/underflow if x is not close to one. if (ax < 0.9999995231628418) return y < 0 ? Double.POSITIVE_INFINITY : 0; if (ax >= 1.0000009536743164) return y > 0 ? Double.POSITIVE_INFINITY : 0; // Now |1-x| is <= 2**-20, sufficient to compute // log(x) by x-x^2/2+x^3/3-x^4/4. t = x - 1; w = t * t * (0.5 - t * (1 / 3.0 - t * 0.25)); u = INV_LN2_H * t; v = t * INV_LN2_L - w * INV_LN2; t1 = (float) (u + v); t2 = v - (t1 - u); } else { long bits = Double.doubleToLongBits(ax); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { ax *= TWO_54; bits = Double.doubleToLongBits(ax); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. ax = Double.longBitsToDouble((bits & 0x000fffffffffffffL) | 0x3ff0000000000000L); boolean k; if (ax < SQRT_1_5) // |x|<sqrt(3/2). k = false; else if (ax < SQRT_3) // |x|<sqrt(3). k = true; else { k = false; ax *= 0.5; exp++; } // Compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5). u = ax - (k ? 1.5 : 1); v = 1 / (ax + (k ? 1.5 : 1)); double s = u * v; double s_h = (float) s; double t_h = (float) (ax + (k ? 1.5 : 1)); double t_l = ax - (t_h - (k ? 1.5 : 1)); double s_l = v * ((u - s_h * t_h) - s_h * t_l); // Compute log(ax). double s2 = s * s; double r = s_l * (s_h + s) + s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6))))); s2 = s_h * s_h; t_h = (float) (3.0 + s2 + r); t_l = r - (t_h - 3.0 - s2); // u+v = s*(1+...). u = s_h * t_h; v = s_l * t_h + t_l * s; // 2/(3log2)*(s+...). double p_h = (float) (u + v); double p_l = v - (p_h - u); double z_h = CP_H * p_h; double z_l = CP_L * p_h + p_l * CP + (k ? DP_L : 0); // log2(ax) = (s+..)*2/(3*log2) = exp + dp_h + z_h + z_l. t = exp; t1 = (float) (z_h + z_l + (k ? DP_H : 0) + t); t2 = z_l - (t1 - t - (k ? DP_H : 0) - z_h); } // Split up y into y1+y2 and compute (y1+y2)*(t1+t2). boolean negative = x < 0 && yisint == 1; double y1 = (float) y; double p_l = (y - y1) * t1 + y * t2; double p_h = y1 * t1; double z = p_l + p_h; if (z >= 1024) // Detect overflow. { if (z > 1024 || p_l + OVT > z - p_h) return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } else if (z <= -1075) // Detect underflow. { if (z < -1075 || p_l <= z - p_h) return negative ? -0.0 : 0; } // Compute 2**(p_h+p_l). int n = round((float) z); p_h -= n; t = (float) (p_l + p_h); u = t * LN2_H; v = (p_l - (t - p_h)) * LN2 + t * LN2_L; z = u + v; w = v - (z - u); t = z * z; t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); double r = (z * t1) / (t1 - 2) - (w + z * w); z = scale(1 - (r - z), n); return negative ? -z : z; }
| 2,276
|
public static double pow(double x, double y) { // Special cases first. if (y == 0) return 1; if (y == 1) return x; if (y == -1) return 1 / x; if (x != x || y != y) return Double.NaN; // When x < 0, yisint tells if y is not an integer (0), even(1), // or odd (2). int yisint = 0; if (x < 0 && floor(y) == y) yisint = (y % 2 == 0) ? 2 : 1; double ax = abs(x); double ay = abs(y); // More special cases, of y. if (ay == Double.POSITIVE_INFINITY) { if (ax == 1) return Double.NaN; if (ax > 1) return y > 0 ? y : 0; return y < 0 ? -y : 0; } if (y == 2) return x * x; if (y == 0.5) return sqrt(x); // More special cases, of x. if (x == 0 || ax == Double.POSITIVE_INFINITY || ax == 1) { if (y < 0) ax = 1 / ax; if (x < 0) { if (x == -1 && yisint == 0) ax = Double.NaN; else if (yisint == 1) ax = -ax; } return ax; } if (x < 0 && yisint == 0) return Double.NaN; // Now we can start! double t; double t1; double t2; double u; double v; double w; if (ay > TWO_31) { if (ay > TWO_64) // Automatic over/underflow. return ((ax < 1) ? y < 0 : y > 0) ? Double.POSITIVE_INFINITY : 0; // Over/underflow if x is not close to one. if (ax < 0.9999995231628418) return y < 0 ? Double.POSITIVE_INFINITY : 0; if (ax >= 1.0000009536743164) return y > 0 ? Double.POSITIVE_INFINITY : 0; // Now |1-x| is <= 2**-20, sufficient to compute // log(x) by x-x^2/2+x^3/3-x^4/4. t = x - 1; w = t * t * (0.5 - t * (1 / 3.0 - t * 0.25)); u = INV_LN2_H * t; v = t * INV_LN2_L - w * INV_LN2; t1 = (float) (u + v); t2 = v - (t1 - u); } else { long bits = Double.doubleToLongBits(ax); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { ax *= TWO_54; bits = Double.doubleToLongBits(ax); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. ax = Double.longBitsToDouble((bits & 0x000fffffffffffffL) | 0x3ff0000000000000L); boolean k; if (ax < SQRT_1_5) // |x|<sqrt(3/2). k = false; else if (ax < SQRT_3) // |x|<sqrt(3). k = true; else { k = false; ax *= 0.5; exp++; } // Compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5). u = ax - (k ? 1.5 : 1); v = 1 / (ax + (k ? 1.5 : 1)); double s = u * v; double s_h = (float) s; double t_h = (float) (ax + (k ? 1.5 : 1)); double t_l = ax - (t_h - (k ? 1.5 : 1)); double s_l = v * ((u - s_h * t_h) - s_h * t_l); // Compute log(ax). double s2 = s * s; double r = s_l * (s_h + s) + s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6))))); s2 = s_h * s_h; t_h = (float) (3.0 + s2 + r); t_l = r - (t_h - 3.0 - s2); // u+v = s*(1+...). u = s_h * t_h; v = s_l * t_h + t_l * s; // 2/(3log2)*(s+...). double p_h = (float) (u + v); double p_l = v - (p_h - u); double z_h = CP_H * p_h; double z_l = CP_L * p_h + p_l * CP + (k ? DP_L : 0); // log2(ax) = (s+..)*2/(3*log2) = exp + dp_h + z_h + z_l. t = exp; t1 = (float) (z_h + z_l + (k ? DP_H : 0) + t); t2 = z_l - (t1 - t - (k ? DP_H : 0) - z_h); } // Split up y into y1+y2 and compute (y1+y2)*(t1+t2). boolean negative = x < 0 && yisint == 1; double y1 = (float) y; double p_l = (y - y1) * t1 + y * t2; double p_h = y1 * t1; double z = p_l + p_h; if (z >= 1024) // Detect overflow. { if (z > 1024 || p_l + OVT > z - p_h) return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } else if (z <= -1075) // Detect underflow. { if (z < -1075 || p_l <= z - p_h) return negative ? -0.0 : 0; } // Compute 2**(p_h+p_l). int n = round((float) z); p_h -= n; t = (float) (p_l + p_h); u = t * LN2_H; v = (p_l - (t - p_h)) * LN2 + t * LN2_L; z = u + v; w = v - (z - u); t = z * z; t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); double r = (z * t1) / (t1 - 2) - (w + z * w); z = scale(1 - (r - z), n); return negative ? -z : z; }
|
public static double pow(double x, double y) { // Special cases first. if (y == 0) return 1; if (y == 1) return x; if (y == -1) return 1 / x; if (x != x || y != y) return Double.NaN; // When x < 0, yisint tells if y is not an integer (0), even(1), // or odd (2). int yisint = 0; if (x < 0 && floor(y) == y) yisint = (y % 2 == 0) ? 2 : 1; double ax = abs(x); double ay = abs(y); // More special cases, of y. if (ay == Double.POSITIVE_INFINITY) { if (ax == 1) return Double.NaN; if (ax > 1) return y > 0 ? y : 0; return y < 0 ? -y : 0; } if (y == 2) return x * x; if (y == 0.5) return sqrt(x); // More special cases, of x. if (x == 0 || ax == Double.POSITIVE_INFINITY || ax == 1) { if (y < 0) ax = 1 / ax; if (x < 0) { if (x == -1 && yisint == 0) ax = Double.NaN; else if (yisint == 1) ax = -ax; } return ax; } if (x < 0 && yisint == 0) return Double.NaN; // Now we can start! double t; double t1; double t2; double u; double v; double w; if (ay > TWO_31) { if (ay > TWO_64) // Automatic over/underflow. return ((ax < 1) ? y < 0 : y > 0) ? Double.POSITIVE_INFINITY : 0; // Over/underflow if x is not close to one. if (ax < 0.9999995231628418) return y < 0 ? Double.POSITIVE_INFINITY : 0; if (ax >= 1.0000009536743164) return y > 0 ? Double.POSITIVE_INFINITY : 0; // Now |1-x| is <= 2**-20, sufficient to compute // log(x) by x-x^2/2+x^3/3-x^4/4. t = x - 1; w = t * t * (0.5 - t * (1 / 3.0 - t * 0.25)); u = INV_LN2_H * t; v = t * INV_LN2_L - w * INV_LN2; t1 = (float) (u + v); t2 = v - (t1 - u); } else { long bits = Double.doubleToLongBits(ax); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { ax *= TWO_54; bits = Double.doubleToLongBits(ax); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. ax = Double.longBitsToDouble((bits & 0x000fffffffffffffL) | 0x3ff0000000000000L); boolean k; if (ax < SQRT_1_5) // |x|<sqrt(3/2). k = false; else if (ax < SQRT_3) // |x|<sqrt(3). k = true; else { k = false; ax *= 0.5; exp++; } // Compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5). u = ax - (k ? 1.5 : 1); v = 1 / (ax + (k ? 1.5 : 1)); double s = u * v; double s_h = (float) s; double t_h = (float) (ax + (k ? 1.5 : 1)); double t_l = ax - (t_h - (k ? 1.5 : 1)); double s_l = v * ((u - s_h * t_h) - s_h * t_l); // Compute log(ax). double s2 = s * s; double r = s_l * (s_h + s) + s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6))))); s2 = s_h * s_h; t_h = (float) (3.0 + s2 + r); t_l = r - (t_h - 3.0 - s2); // u+v = s*(1+...). u = s_h * t_h; v = s_l * t_h + t_l * s; // 2/(3log2)*(s+...). double p_h = (float) (u + v); double p_l = v - (p_h - u); double z_h = CP_H * p_h; double z_l = CP_L * p_h + p_l * CP + (k ? DP_L : 0); // log2(ax) = (s+..)*2/(3*log2) = exp + dp_h + z_h + z_l. t = exp; t1 = (float) (z_h + z_l + (k ? DP_H : 0) + t); t2 = z_l - (t1 - t - (k ? DP_H : 0) - z_h); } // Split up y into y1+y2 and compute (y1+y2)*(t1+t2). boolean negative = x < 0 && yisint == 1; double y1 = (float) y; double p_l = (y - y1) * t1 + y * t2; double p_h = y1 * t1; double z = p_l + p_h; if (z >= 1024) // Detect overflow. { if (z > 1024 || p_l + OVT > z - p_h) return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } else if (z <= -1075) // Detect underflow. { if (z < -1075 || p_l <= z - p_h) return negative ? -0.0 : 0; } // Compute 2**(p_h+p_l). int n = round((float) z); p_h -= n; t = (float) (p_l + p_h); u = t * LN2_H; v = (p_l - (t - p_h)) * LN2 + t * LN2_L; z = u + v; w = v - (z - u); t = z * z; t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); double r = (z * t1) / (t1 - 2) - (w + z * w); z = scale(1 - (r - z), n); return negative ? -z : z; }
| 2,277
|
public static double pow(double x, double y) { // Special cases first. if (y == 0) return 1; if (y == 1) return x; if (y == -1) return 1 / x; if (x != x || y != y) return Double.NaN; // When x < 0, yisint tells if y is not an integer (0), even(1), // or odd (2). int yisint = 0; if (x < 0 && floor(y) == y) yisint = (y % 2 == 0) ? 2 : 1; double ax = abs(x); double ay = abs(y); // More special cases, of y. if (ay == Double.POSITIVE_INFINITY) { if (ax == 1) return Double.NaN; if (ax > 1) return y > 0 ? y : 0; return y < 0 ? -y : 0; } if (y == 2) return x * x; if (y == 0.5) return sqrt(x); // More special cases, of x. if (x == 0 || ax == Double.POSITIVE_INFINITY || ax == 1) { if (y < 0) ax = 1 / ax; if (x < 0) { if (x == -1 && yisint == 0) ax = Double.NaN; else if (yisint == 1) ax = -ax; } return ax; } if (x < 0 && yisint == 0) return Double.NaN; // Now we can start! double t; double t1; double t2; double u; double v; double w; if (ay > TWO_31) { if (ay > TWO_64) // Automatic over/underflow. return ((ax < 1) ? y < 0 : y > 0) ? Double.POSITIVE_INFINITY : 0; // Over/underflow if x is not close to one. if (ax < 0.9999995231628418) return y < 0 ? Double.POSITIVE_INFINITY : 0; if (ax >= 1.0000009536743164) return y > 0 ? Double.POSITIVE_INFINITY : 0; // Now |1-x| is <= 2**-20, sufficient to compute // log(x) by x-x^2/2+x^3/3-x^4/4. t = x - 1; w = t * t * (0.5 - t * (1 / 3.0 - t * 0.25)); u = INV_LN2_H * t; v = t * INV_LN2_L - w * INV_LN2; t1 = (float) (u + v); t2 = v - (t1 - u); } else { long bits = Double.doubleToLongBits(ax); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { ax *= TWO_54; bits = Double.doubleToLongBits(ax); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. ax = Double.longBitsToDouble((bits & 0x000fffffffffffffL) | 0x3ff0000000000000L); boolean k; if (ax < SQRT_1_5) // |x|<sqrt(3/2). k = false; else if (ax < SQRT_3) // |x|<sqrt(3). k = true; else { k = false; ax *= 0.5; exp++; } // Compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5). u = ax - (k ? 1.5 : 1); v = 1 / (ax + (k ? 1.5 : 1)); double s = u * v; double s_h = (float) s; double t_h = (float) (ax + (k ? 1.5 : 1)); double t_l = ax - (t_h - (k ? 1.5 : 1)); double s_l = v * ((u - s_h * t_h) - s_h * t_l); // Compute log(ax). double s2 = s * s; double r = s_l * (s_h + s) + s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6))))); s2 = s_h * s_h; t_h = (float) (3.0 + s2 + r); t_l = r - (t_h - 3.0 - s2); // u+v = s*(1+...). u = s_h * t_h; v = s_l * t_h + t_l * s; // 2/(3log2)*(s+...). double p_h = (float) (u + v); double p_l = v - (p_h - u); double z_h = CP_H * p_h; double z_l = CP_L * p_h + p_l * CP + (k ? DP_L : 0); // log2(ax) = (s+..)*2/(3*log2) = exp + dp_h + z_h + z_l. t = exp; t1 = (float) (z_h + z_l + (k ? DP_H : 0) + t); t2 = z_l - (t1 - t - (k ? DP_H : 0) - z_h); } // Split up y into y1+y2 and compute (y1+y2)*(t1+t2). boolean negative = x < 0 && yisint == 1; double y1 = (float) y; double p_l = (y - y1) * t1 + y * t2; double p_h = y1 * t1; double z = p_l + p_h; if (z >= 1024) // Detect overflow. { if (z > 1024 || p_l + OVT > z - p_h) return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } else if (z <= -1075) // Detect underflow. { if (z < -1075 || p_l <= z - p_h) return negative ? -0.0 : 0; } // Compute 2**(p_h+p_l). int n = round((float) z); p_h -= n; t = (float) (p_l + p_h); u = t * LN2_H; v = (p_l - (t - p_h)) * LN2 + t * LN2_L; z = u + v; w = v - (z - u); t = z * z; t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); double r = (z * t1) / (t1 - 2) - (w + z * w); z = scale(1 - (r - z), n); return negative ? -z : z; }
|
public static double pow(double x, double y) { // Special cases first. if (y == 0) return 1; if (y == 1) return x; if (y == -1) return 1 / x; if (x != x || y != y) return Double.NaN; // When x < 0, yisint tells if y is not an integer (0), even(1), // or odd (2). int yisint = 0; if (x < 0 && floor(y) == y) yisint = (y % 2 == 0) ? 2 : 1; double ax = abs(x); double ay = abs(y); // More special cases, of y. if (ay == Double.POSITIVE_INFINITY) { if (ax == 1) return Double.NaN; if (ax > 1) return y > 0 ? y : 0; return y < 0 ? -y : 0; } if (y == 2) return x * x; if (y == 0.5) return sqrt(x); // More special cases, of x. if (x == 0 || ax == Double.POSITIVE_INFINITY || ax == 1) { if (y < 0) ax = 1 / ax; if (x < 0) { if (x == -1 && yisint == 0) ax = Double.NaN; else if (yisint == 1) ax = -ax; } return ax; } if (x < 0 && yisint == 0) return Double.NaN; // Now we can start! double t; double t1; double t2; double u; double v; double w; if (ay > TWO_31) { if (ay > TWO_64) // Automatic over/underflow. return ((ax < 1) ? y < 0 : y > 0) ? Double.POSITIVE_INFINITY : 0; // Over/underflow if x is not close to one. if (ax < 0.9999995231628418) return y < 0 ? Double.POSITIVE_INFINITY : 0; if (ax >= 1.0000009536743164) return y > 0 ? Double.POSITIVE_INFINITY : 0; // Now |1-x| is <= 2**-20, sufficient to compute // log(x) by x-x^2/2+x^3/3-x^4/4. t = x - 1; w = t * t * (0.5 - t * (1 / 3.0 - t * 0.25)); u = INV_LN2_H * t; v = t * INV_LN2_L - w * INV_LN2; t1 = (float) (u + v); t2 = v - (t1 - u); } else { long bits = Double.doubleToLongBits(ax); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { ax *= TWO_54; bits = Double.doubleToLongBits(ax); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. ax = Double.longBitsToDouble((bits & 0x000fffffffffffffL) | 0x3ff0000000000000L); boolean k; if (ax < SQRT_1_5) // |x|<sqrt(3/2). k = false; else if (ax < SQRT_3) // |x|<sqrt(3). k = true; else { k = false; ax *= 0.5; exp++; } // Compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5). u = ax - (k ? 1.5 : 1); v = 1 / (ax + (k ? 1.5 : 1)); double s = u * v; double s_h = (float) s; double t_h = (float) (ax + (k ? 1.5 : 1)); double t_l = ax - (t_h - (k ? 1.5 : 1)); double s_l = v * ((u - s_h * t_h) - s_h * t_l); // Compute log(ax). double s2 = s * s; double r = s_l * (s_h + s) + s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6))))); s2 = s_h * s_h; t_h = (float) (3.0 + s2 + r); t_l = r - (t_h - 3.0 - s2); // u+v = s*(1+...). u = s_h * t_h; v = s_l * t_h + t_l * s; // 2/(3log2)*(s+...). double p_h = (float) (u + v); double p_l = v - (p_h - u); double z_h = CP_H * p_h; double z_l = CP_L * p_h + p_l * CP + (k ? DP_L : 0); // log2(ax) = (s+..)*2/(3*log2) = exp + dp_h + z_h + z_l. t = exp; t1 = (float) (z_h + z_l + (k ? DP_H : 0) + t); t2 = z_l - (t1 - t - (k ? DP_H : 0) - z_h); } // Split up y into y1+y2 and compute (y1+y2)*(t1+t2). boolean negative = x < 0 && yisint == 1; double y1 = (float) y; double p_l = (y - y1) * t1 + y * t2; double p_h = y1 * t1; double z = p_l + p_h; if (z >= 1024) // Detect overflow. { if (z > 1024 || p_l + OVT > z - p_h) return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } else if (z <= -1075) // Detect underflow. { if (z < -1075 || p_l <= z - p_h) return negative ? -0.0 : 0; } // Compute 2**(p_h+p_l). int n = round((float) z); p_h -= n; t = (float) (p_l + p_h); u = t * LN2_H; v = (p_l - (t - p_h)) * LN2 + t * LN2_L; z = u + v; w = v - (z - u); t = z * z; t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); double r = (z * t1) / (t1 - 2) - (w + z * w); z = scale(1 - (r - z), n); return negative ? -z : z; }
| 2,278
|
public static double pow(double x, double y) { // Special cases first. if (y == 0) return 1; if (y == 1) return x; if (y == -1) return 1 / x; if (x != x || y != y) return Double.NaN; // When x < 0, yisint tells if y is not an integer (0), even(1), // or odd (2). int yisint = 0; if (x < 0 && floor(y) == y) yisint = (y % 2 == 0) ? 2 : 1; double ax = abs(x); double ay = abs(y); // More special cases, of y. if (ay == Double.POSITIVE_INFINITY) { if (ax == 1) return Double.NaN; if (ax > 1) return y > 0 ? y : 0; return y < 0 ? -y : 0; } if (y == 2) return x * x; if (y == 0.5) return sqrt(x); // More special cases, of x. if (x == 0 || ax == Double.POSITIVE_INFINITY || ax == 1) { if (y < 0) ax = 1 / ax; if (x < 0) { if (x == -1 && yisint == 0) ax = Double.NaN; else if (yisint == 1) ax = -ax; } return ax; } if (x < 0 && yisint == 0) return Double.NaN; // Now we can start! double t; double t1; double t2; double u; double v; double w; if (ay > TWO_31) { if (ay > TWO_64) // Automatic over/underflow. return ((ax < 1) ? y < 0 : y > 0) ? Double.POSITIVE_INFINITY : 0; // Over/underflow if x is not close to one. if (ax < 0.9999995231628418) return y < 0 ? Double.POSITIVE_INFINITY : 0; if (ax >= 1.0000009536743164) return y > 0 ? Double.POSITIVE_INFINITY : 0; // Now |1-x| is <= 2**-20, sufficient to compute // log(x) by x-x^2/2+x^3/3-x^4/4. t = x - 1; w = t * t * (0.5 - t * (1 / 3.0 - t * 0.25)); u = INV_LN2_H * t; v = t * INV_LN2_L - w * INV_LN2; t1 = (float) (u + v); t2 = v - (t1 - u); } else { long bits = Double.doubleToLongBits(ax); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { ax *= TWO_54; bits = Double.doubleToLongBits(ax); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. ax = Double.longBitsToDouble((bits & 0x000fffffffffffffL) | 0x3ff0000000000000L); boolean k; if (ax < SQRT_1_5) // |x|<sqrt(3/2). k = false; else if (ax < SQRT_3) // |x|<sqrt(3). k = true; else { k = false; ax *= 0.5; exp++; } // Compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5). u = ax - (k ? 1.5 : 1); v = 1 / (ax + (k ? 1.5 : 1)); double s = u * v; double s_h = (float) s; double t_h = (float) (ax + (k ? 1.5 : 1)); double t_l = ax - (t_h - (k ? 1.5 : 1)); double s_l = v * ((u - s_h * t_h) - s_h * t_l); // Compute log(ax). double s2 = s * s; double r = s_l * (s_h + s) + s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6))))); s2 = s_h * s_h; t_h = (float) (3.0 + s2 + r); t_l = r - (t_h - 3.0 - s2); // u+v = s*(1+...). u = s_h * t_h; v = s_l * t_h + t_l * s; // 2/(3log2)*(s+...). double p_h = (float) (u + v); double p_l = v - (p_h - u); double z_h = CP_H * p_h; double z_l = CP_L * p_h + p_l * CP + (k ? DP_L : 0); // log2(ax) = (s+..)*2/(3*log2) = exp + dp_h + z_h + z_l. t = exp; t1 = (float) (z_h + z_l + (k ? DP_H : 0) + t); t2 = z_l - (t1 - t - (k ? DP_H : 0) - z_h); } // Split up y into y1+y2 and compute (y1+y2)*(t1+t2). boolean negative = x < 0 && yisint == 1; double y1 = (float) y; double p_l = (y - y1) * t1 + y * t2; double p_h = y1 * t1; double z = p_l + p_h; if (z >= 1024) // Detect overflow. { if (z > 1024 || p_l + OVT > z - p_h) return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } else if (z <= -1075) // Detect underflow. { if (z < -1075 || p_l <= z - p_h) return negative ? -0.0 : 0; } // Compute 2**(p_h+p_l). int n = round((float) z); p_h -= n; t = (float) (p_l + p_h); u = t * LN2_H; v = (p_l - (t - p_h)) * LN2 + t * LN2_L; z = u + v; w = v - (z - u); t = z * z; t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); double r = (z * t1) / (t1 - 2) - (w + z * w); z = scale(1 - (r - z), n); return negative ? -z : z; }
|
public static double pow(double x, double y) { // Special cases first. if (y == 0) return 1; if (y == 1) return x; if (y == -1) return 1 / x; if (x != x || y != y) return Double.NaN; // When x < 0, yisint tells if y is not an integer (0), even(1), // or odd (2). int yisint = 0; if (x < 0 && floor(y) == y) yisint = (y % 2 == 0) ? 2 : 1; double ax = abs(x); double ay = abs(y); // More special cases, of y. if (ay == Double.POSITIVE_INFINITY) { if (ax == 1) return Double.NaN; if (ax > 1) return y > 0 ? y : 0; return y < 0 ? -y : 0; } if (y == 2) return x * x; if (y == 0.5) return sqrt(x); // More special cases, of x. if (x == 0 || ax == Double.POSITIVE_INFINITY || ax == 1) { if (y < 0) ax = 1 / ax; if (x < 0) { if (x == -1 && yisint == 0) ax = Double.NaN; else if (yisint == 1) ax = -ax; } return ax; } if (x < 0 && yisint == 0) return Double.NaN; // Now we can start! double t; double t1; double t2; double u; double v; double w; if (ay > TWO_31) { if (ay > TWO_64) // Automatic over/underflow. return ((ax < 1) ? y < 0 : y > 0) ? Double.POSITIVE_INFINITY : 0; // Over/underflow if x is not close to one. if (ax < 0.9999995231628418) return y < 0 ? Double.POSITIVE_INFINITY : 0; if (ax >= 1.0000009536743164) return y > 0 ? Double.POSITIVE_INFINITY : 0; // Now |1-x| is <= 2**-20, sufficient to compute // log(x) by x-x^2/2+x^3/3-x^4/4. t = x - 1; w = t * t * (0.5 - t * (1 / 3.0 - t * 0.25)); u = INV_LN2_H * t; v = t * INV_LN2_L - w * INV_LN2; t1 = (float) (u + v); t2 = v - (t1 - u); } else { long bits = Double.doubleToLongBits(ax); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { ax *= TWO_54; bits = Double.doubleToLongBits(ax); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. ax = Double.longBitsToDouble((bits & 0x000fffffffffffffL) | 0x3ff0000000000000L); boolean k; if (ax < SQRT_1_5) // |x|<sqrt(3/2). k = false; else if (ax < SQRT_3) // |x|<sqrt(3). k = true; else { k = false; ax *= 0.5; exp++; } // Compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5). u = ax - (k ? 1.5 : 1); v = 1 / (ax + (k ? 1.5 : 1)); double s = u * v; double s_h = (float) s; double t_h = (float) (ax + (k ? 1.5 : 1)); double t_l = ax - (t_h - (k ? 1.5 : 1)); double s_l = v * ((u - s_h * t_h) - s_h * t_l); // Compute log(ax). double s2 = s * s; double r = s_l * (s_h + s) + s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6))))); s2 = s_h * s_h; t_h = (float) (3.0 + s2 + r); t_l = r - (t_h - 3.0 - s2); // u+v = s*(1+...). u = s_h * t_h; v = s_l * t_h + t_l * s; // 2/(3log2)*(s+...). double p_h = (float) (u + v); double p_l = v - (p_h - u); double z_h = CP_H * p_h; double z_l = CP_L * p_h + p_l * CP + (k ? DP_L : 0); // log2(ax) = (s+..)*2/(3*log2) = exp + dp_h + z_h + z_l. t = exp; t1 = (float) (z_h + z_l + (k ? DP_H : 0) + t); t2 = z_l - (t1 - t - (k ? DP_H : 0) - z_h); } // Split up y into y1+y2 and compute (y1+y2)*(t1+t2). boolean negative = x < 0 && yisint == 1; double y1 = (float) y; double p_l = (y - y1) * t1 + y * t2; double p_h = y1 * t1; double z = p_l + p_h; if (z >= 1024) // Detect overflow. { if (z > 1024 || p_l + OVT > z - p_h) return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } else if (z <= -1075) // Detect underflow. { if (z < -1075 || p_l <= z - p_h) return negative ? -0.0 : 0; } // Compute 2**(p_h+p_l). int n = round((float) z); p_h -= n; t = (float) (p_l + p_h); u = t * LN2_H; v = (p_l - (t - p_h)) * LN2 + t * LN2_L; z = u + v; w = v - (z - u); t = z * z; t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); double r = (z * t1) / (t1 - 2) - (w + z * w); z = scale(1 - (r - z), n); return negative ? -z : z; }
| 2,279
|
public static double pow(double x, double y) { // Special cases first. if (y == 0) return 1; if (y == 1) return x; if (y == -1) return 1 / x; if (x != x || y != y) return Double.NaN; // When x < 0, yisint tells if y is not an integer (0), even(1), // or odd (2). int yisint = 0; if (x < 0 && floor(y) == y) yisint = (y % 2 == 0) ? 2 : 1; double ax = abs(x); double ay = abs(y); // More special cases, of y. if (ay == Double.POSITIVE_INFINITY) { if (ax == 1) return Double.NaN; if (ax > 1) return y > 0 ? y : 0; return y < 0 ? -y : 0; } if (y == 2) return x * x; if (y == 0.5) return sqrt(x); // More special cases, of x. if (x == 0 || ax == Double.POSITIVE_INFINITY || ax == 1) { if (y < 0) ax = 1 / ax; if (x < 0) { if (x == -1 && yisint == 0) ax = Double.NaN; else if (yisint == 1) ax = -ax; } return ax; } if (x < 0 && yisint == 0) return Double.NaN; // Now we can start! double t; double t1; double t2; double u; double v; double w; if (ay > TWO_31) { if (ay > TWO_64) // Automatic over/underflow. return ((ax < 1) ? y < 0 : y > 0) ? Double.POSITIVE_INFINITY : 0; // Over/underflow if x is not close to one. if (ax < 0.9999995231628418) return y < 0 ? Double.POSITIVE_INFINITY : 0; if (ax >= 1.0000009536743164) return y > 0 ? Double.POSITIVE_INFINITY : 0; // Now |1-x| is <= 2**-20, sufficient to compute // log(x) by x-x^2/2+x^3/3-x^4/4. t = x - 1; w = t * t * (0.5 - t * (1 / 3.0 - t * 0.25)); u = INV_LN2_H * t; v = t * INV_LN2_L - w * INV_LN2; t1 = (float) (u + v); t2 = v - (t1 - u); } else { long bits = Double.doubleToLongBits(ax); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { ax *= TWO_54; bits = Double.doubleToLongBits(ax); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. ax = Double.longBitsToDouble((bits & 0x000fffffffffffffL) | 0x3ff0000000000000L); boolean k; if (ax < SQRT_1_5) // |x|<sqrt(3/2). k = false; else if (ax < SQRT_3) // |x|<sqrt(3). k = true; else { k = false; ax *= 0.5; exp++; } // Compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5). u = ax - (k ? 1.5 : 1); v = 1 / (ax + (k ? 1.5 : 1)); double s = u * v; double s_h = (float) s; double t_h = (float) (ax + (k ? 1.5 : 1)); double t_l = ax - (t_h - (k ? 1.5 : 1)); double s_l = v * ((u - s_h * t_h) - s_h * t_l); // Compute log(ax). double s2 = s * s; double r = s_l * (s_h + s) + s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6))))); s2 = s_h * s_h; t_h = (float) (3.0 + s2 + r); t_l = r - (t_h - 3.0 - s2); // u+v = s*(1+...). u = s_h * t_h; v = s_l * t_h + t_l * s; // 2/(3log2)*(s+...). double p_h = (float) (u + v); double p_l = v - (p_h - u); double z_h = CP_H * p_h; double z_l = CP_L * p_h + p_l * CP + (k ? DP_L : 0); // log2(ax) = (s+..)*2/(3*log2) = exp + dp_h + z_h + z_l. t = exp; t1 = (float) (z_h + z_l + (k ? DP_H : 0) + t); t2 = z_l - (t1 - t - (k ? DP_H : 0) - z_h); } // Split up y into y1+y2 and compute (y1+y2)*(t1+t2). boolean negative = x < 0 && yisint == 1; double y1 = (float) y; double p_l = (y - y1) * t1 + y * t2; double p_h = y1 * t1; double z = p_l + p_h; if (z >= 1024) // Detect overflow. { if (z > 1024 || p_l + OVT > z - p_h) return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } else if (z <= -1075) // Detect underflow. { if (z < -1075 || p_l <= z - p_h) return negative ? -0.0 : 0; } // Compute 2**(p_h+p_l). int n = round((float) z); p_h -= n; t = (float) (p_l + p_h); u = t * LN2_H; v = (p_l - (t - p_h)) * LN2 + t * LN2_L; z = u + v; w = v - (z - u); t = z * z; t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); double r = (z * t1) / (t1 - 2) - (w + z * w); z = scale(1 - (r - z), n); return negative ? -z : z; }
|
public static double pow(double x, double y) { // Special cases first. if (y == 0) return 1; if (y == 1) return x; if (y == -1) return 1 / x; if (x != x || y != y) return Double.NaN; // When x < 0, yisint tells if y is not an integer (0), even(1), // or odd (2). int yisint = 0; if (x < 0 && floor(y) == y) yisint = (y % 2 == 0) ? 2 : 1; double ax = abs(x); double ay = abs(y); // More special cases, of y. if (ay == Double.POSITIVE_INFINITY) { if (ax == 1) return Double.NaN; if (ax > 1) return y > 0 ? y : 0; return y < 0 ? -y : 0; } if (y == 2) return x * x; if (y == 0.5) return sqrt(x); // More special cases, of x. if (x == 0 || ax == Double.POSITIVE_INFINITY || ax == 1) { if (y < 0) ax = 1 / ax; if (x < 0) { if (x == -1 && yisint == 0) ax = Double.NaN; else if (yisint == 1) ax = -ax; } return ax; } if (x < 0 && yisint == 0) return Double.NaN; // Now we can start! double t; double t1; double t2; double u; double v; double w; if (ay > TWO_31) { if (ay > TWO_64) // Automatic over/underflow. return ((ax < 1) ? y < 0 : y > 0) ? Double.POSITIVE_INFINITY : 0; // Over/underflow if x is not close to one. if (ax < 0.9999995231628418) return y < 0 ? Double.POSITIVE_INFINITY : 0; if (ax >= 1.0000009536743164) return y > 0 ? Double.POSITIVE_INFINITY : 0; // Now |1-x| is <= 2**-20, sufficient to compute // log(x) by x-x^2/2+x^3/3-x^4/4. t = x - 1; w = t * t * (0.5 - t * (1 / 3.0 - t * 0.25)); u = INV_LN2_H * t; v = t * INV_LN2_L - w * INV_LN2; t1 = (float) (u + v); t2 = v - (t1 - u); } else { long bits = Double.doubleToLongBits(ax); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { ax *= TWO_54; bits = Double.doubleToLongBits(ax); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. ax = Double.longBitsToDouble((bits & 0x000fffffffffffffL) | 0x3ff0000000000000L); boolean k; if (ax < SQRT_1_5) // |x|<sqrt(3/2). k = false; else if (ax < SQRT_3) // |x|<sqrt(3). k = true; else { k = false; ax *= 0.5; exp++; } // Compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5). u = ax - (k ? 1.5 : 1); v = 1 / (ax + (k ? 1.5 : 1)); double s = u * v; double s_h = (float) s; double t_h = (float) (ax + (k ? 1.5 : 1)); double t_l = ax - (t_h - (k ? 1.5 : 1)); double s_l = v * ((u - s_h * t_h) - s_h * t_l); // Compute log(ax). double s2 = s * s; double r = s_l * (s_h + s) + s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6))))); s2 = s_h * s_h; t_h = (float) (3.0 + s2 + r); t_l = r - (t_h - 3.0 - s2); // u+v = s*(1+...). u = s_h * t_h; v = s_l * t_h + t_l * s; // 2/(3log2)*(s+...). double p_h = (float) (u + v); double p_l = v - (p_h - u); double z_h = CP_H * p_h; double z_l = CP_L * p_h + p_l * CP + (k ? DP_L : 0); // log2(ax) = (s+..)*2/(3*log2) = exp + dp_h + z_h + z_l. t = exp; t1 = (float) (z_h + z_l + (k ? DP_H : 0) + t); t2 = z_l - (t1 - t - (k ? DP_H : 0) - z_h); } // Split up y into y1+y2 and compute (y1+y2)*(t1+t2). boolean negative = x < 0 && yisint == 1; double y1 = (float) y; double p_l = (y - y1) * t1 + y * t2; double p_h = y1 * t1; double z = p_l + p_h; if (z >= 1024) // Detect overflow. { if (z > 1024 || p_l + OVT > z - p_h) return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } else if (z <= -1075) // Detect underflow. { if (z < -1075 || p_l <= z - p_h) return negative ? -0.0 : 0; } // Compute 2**(p_h+p_l). int n = round((float) z); p_h -= n; t = (float) (p_l + p_h); u = t * LN2_H; v = (p_l - (t - p_h)) * LN2 + t * LN2_L; z = u + v; w = v - (z - u); t = z * z; t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); double r = (z * t1) / (t1 - 2) - (w + z * w); z = scale(1 - (r - z), n); return negative ? -z : z; }
| 2,280
|
public static double pow(double x, double y) { // Special cases first. if (y == 0) return 1; if (y == 1) return x; if (y == -1) return 1 / x; if (x != x || y != y) return Double.NaN; // When x < 0, yisint tells if y is not an integer (0), even(1), // or odd (2). int yisint = 0; if (x < 0 && floor(y) == y) yisint = (y % 2 == 0) ? 2 : 1; double ax = abs(x); double ay = abs(y); // More special cases, of y. if (ay == Double.POSITIVE_INFINITY) { if (ax == 1) return Double.NaN; if (ax > 1) return y > 0 ? y : 0; return y < 0 ? -y : 0; } if (y == 2) return x * x; if (y == 0.5) return sqrt(x); // More special cases, of x. if (x == 0 || ax == Double.POSITIVE_INFINITY || ax == 1) { if (y < 0) ax = 1 / ax; if (x < 0) { if (x == -1 && yisint == 0) ax = Double.NaN; else if (yisint == 1) ax = -ax; } return ax; } if (x < 0 && yisint == 0) return Double.NaN; // Now we can start! double t; double t1; double t2; double u; double v; double w; if (ay > TWO_31) { if (ay > TWO_64) // Automatic over/underflow. return ((ax < 1) ? y < 0 : y > 0) ? Double.POSITIVE_INFINITY : 0; // Over/underflow if x is not close to one. if (ax < 0.9999995231628418) return y < 0 ? Double.POSITIVE_INFINITY : 0; if (ax >= 1.0000009536743164) return y > 0 ? Double.POSITIVE_INFINITY : 0; // Now |1-x| is <= 2**-20, sufficient to compute // log(x) by x-x^2/2+x^3/3-x^4/4. t = x - 1; w = t * t * (0.5 - t * (1 / 3.0 - t * 0.25)); u = INV_LN2_H * t; v = t * INV_LN2_L - w * INV_LN2; t1 = (float) (u + v); t2 = v - (t1 - u); } else { long bits = Double.doubleToLongBits(ax); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { ax *= TWO_54; bits = Double.doubleToLongBits(ax); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. ax = Double.longBitsToDouble((bits & 0x000fffffffffffffL) | 0x3ff0000000000000L); boolean k; if (ax < SQRT_1_5) // |x|<sqrt(3/2). k = false; else if (ax < SQRT_3) // |x|<sqrt(3). k = true; else { k = false; ax *= 0.5; exp++; } // Compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5). u = ax - (k ? 1.5 : 1); v = 1 / (ax + (k ? 1.5 : 1)); double s = u * v; double s_h = (float) s; double t_h = (float) (ax + (k ? 1.5 : 1)); double t_l = ax - (t_h - (k ? 1.5 : 1)); double s_l = v * ((u - s_h * t_h) - s_h * t_l); // Compute log(ax). double s2 = s * s; double r = s_l * (s_h + s) + s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6))))); s2 = s_h * s_h; t_h = (float) (3.0 + s2 + r); t_l = r - (t_h - 3.0 - s2); // u+v = s*(1+...). u = s_h * t_h; v = s_l * t_h + t_l * s; // 2/(3log2)*(s+...). double p_h = (float) (u + v); double p_l = v - (p_h - u); double z_h = CP_H * p_h; double z_l = CP_L * p_h + p_l * CP + (k ? DP_L : 0); // log2(ax) = (s+..)*2/(3*log2) = exp + dp_h + z_h + z_l. t = exp; t1 = (float) (z_h + z_l + (k ? DP_H : 0) + t); t2 = z_l - (t1 - t - (k ? DP_H : 0) - z_h); } // Split up y into y1+y2 and compute (y1+y2)*(t1+t2). boolean negative = x < 0 && yisint == 1; double y1 = (float) y; double p_l = (y - y1) * t1 + y * t2; double p_h = y1 * t1; double z = p_l + p_h; if (z >= 1024) // Detect overflow. { if (z > 1024 || p_l + OVT > z - p_h) return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } else if (z <= -1075) // Detect underflow. { if (z < -1075 || p_l <= z - p_h) return negative ? -0.0 : 0; } // Compute 2**(p_h+p_l). int n = round((float) z); p_h -= n; t = (float) (p_l + p_h); u = t * LN2_H; v = (p_l - (t - p_h)) * LN2 + t * LN2_L; z = u + v; w = v - (z - u); t = z * z; t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); double r = (z * t1) / (t1 - 2) - (w + z * w); z = scale(1 - (r - z), n); return negative ? -z : z; }
|
public static double pow(double x, double y) { // Special cases first. if (y == 0) return 1; if (y == 1) return x; if (y == -1) return 1 / x; if (x != x || y != y) return Double.NaN; // When x < 0, yisint tells if y is not an integer (0), even(1), // or odd (2). int yisint = 0; if (x < 0 && floor(y) == y) yisint = (y % 2 == 0) ? 2 : 1; double ax = abs(x); double ay = abs(y); // More special cases, of y. if (ay == Double.POSITIVE_INFINITY) { if (ax == 1) return Double.NaN; if (ax > 1) return y > 0 ? y : 0; return y < 0 ? -y : 0; } if (y == 2) return x * x; if (y == 0.5) return sqrt(x); // More special cases, of x. if (x == 0 || ax == Double.POSITIVE_INFINITY || ax == 1) { if (y < 0) ax = 1 / ax; if (x < 0) { if (x == -1 && yisint == 0) ax = Double.NaN; else if (yisint == 1) ax = -ax; } return ax; } if (x < 0 && yisint == 0) return Double.NaN; // Now we can start! double t; double t1; double t2; double u; double v; double w; if (ay > TWO_31) { if (ay > TWO_64) // Automatic over/underflow. return ((ax < 1) ? y < 0 : y > 0) ? Double.POSITIVE_INFINITY : 0; // Over/underflow if x is not close to one. if (ax < 0.9999995231628418) return y < 0 ? Double.POSITIVE_INFINITY : 0; if (ax >= 1.0000009536743164) return y > 0 ? Double.POSITIVE_INFINITY : 0; // Now |1-x| is <= 2**-20, sufficient to compute // log(x) by x-x^2/2+x^3/3-x^4/4. t = x - 1; w = t * t * (0.5 - t * (1 / 3.0 - t * 0.25)); u = INV_LN2_H * t; v = t * INV_LN2_L - w * INV_LN2; t1 = (float) (u + v); t2 = v - (t1 - u); } else { long bits = Double.doubleToLongBits(ax); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { ax *= TWO_54; bits = Double.doubleToLongBits(ax); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. ax = Double.longBitsToDouble((bits & 0x000fffffffffffffL) | 0x3ff0000000000000L); boolean k; if (ax < SQRT_1_5) // |x|<sqrt(3/2). k = false; else if (ax < SQRT_3) // |x|<sqrt(3). k = true; else { k = false; ax *= 0.5; exp++; } // Compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5). u = ax - (k ? 1.5 : 1); v = 1 / (ax + (k ? 1.5 : 1)); double s = u * v; double s_h = (float) s; double t_h = (float) (ax + (k ? 1.5 : 1)); double t_l = ax - (t_h - (k ? 1.5 : 1)); double s_l = v * ((u - s_h * t_h) - s_h * t_l); // Compute log(ax). double s2 = s * s; double r = s_l * (s_h + s) + s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6))))); s2 = s_h * s_h; t_h = (float) (3.0 + s2 + r); t_l = r - (t_h - 3.0 - s2); // u+v = s*(1+...). u = s_h * t_h; v = s_l * t_h + t_l * s; // 2/(3log2)*(s+...). double p_h = (float) (u + v); double p_l = v - (p_h - u); double z_h = CP_H * p_h; double z_l = CP_L * p_h + p_l * CP + (k ? DP_L : 0); // log2(ax) = (s+..)*2/(3*log2) = exp + dp_h + z_h + z_l. t = exp; t1 = (float) (z_h + z_l + (k ? DP_H : 0) + t); t2 = z_l - (t1 - t - (k ? DP_H : 0) - z_h); } // Split up y into y1+y2 and compute (y1+y2)*(t1+t2). boolean negative = x < 0 && yisint == 1; double y1 = (float) y; double p_l = (y - y1) * t1 + y * t2; double p_h = y1 * t1; double z = p_l + p_h; if (z >= 1024) // Detect overflow. { if (z > 1024 || p_l + OVT > z - p_h) return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } else if (z <= -1075) // Detect underflow. { if (z < -1075 || p_l <= z - p_h) return negative ? -0.0 : 0; } // Compute 2**(p_h+p_l). int n = round((float) z); p_h -= n; t = (float) (p_l + p_h); u = t * LN2_H; v = (p_l - (t - p_h)) * LN2 + t * LN2_L; z = u + v; w = v - (z - u); t = z * z; t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); double r = (z * t1) / (t1 - 2) - (w + z * w); z = scale(1 - (r - z), n); return negative ? -z : z; }
| 2,281
|
public static double pow(double x, double y) { // Special cases first. if (y == 0) return 1; if (y == 1) return x; if (y == -1) return 1 / x; if (x != x || y != y) return Double.NaN; // When x < 0, yisint tells if y is not an integer (0), even(1), // or odd (2). int yisint = 0; if (x < 0 && floor(y) == y) yisint = (y % 2 == 0) ? 2 : 1; double ax = abs(x); double ay = abs(y); // More special cases, of y. if (ay == Double.POSITIVE_INFINITY) { if (ax == 1) return Double.NaN; if (ax > 1) return y > 0 ? y : 0; return y < 0 ? -y : 0; } if (y == 2) return x * x; if (y == 0.5) return sqrt(x); // More special cases, of x. if (x == 0 || ax == Double.POSITIVE_INFINITY || ax == 1) { if (y < 0) ax = 1 / ax; if (x < 0) { if (x == -1 && yisint == 0) ax = Double.NaN; else if (yisint == 1) ax = -ax; } return ax; } if (x < 0 && yisint == 0) return Double.NaN; // Now we can start! double t; double t1; double t2; double u; double v; double w; if (ay > TWO_31) { if (ay > TWO_64) // Automatic over/underflow. return ((ax < 1) ? y < 0 : y > 0) ? Double.POSITIVE_INFINITY : 0; // Over/underflow if x is not close to one. if (ax < 0.9999995231628418) return y < 0 ? Double.POSITIVE_INFINITY : 0; if (ax >= 1.0000009536743164) return y > 0 ? Double.POSITIVE_INFINITY : 0; // Now |1-x| is <= 2**-20, sufficient to compute // log(x) by x-x^2/2+x^3/3-x^4/4. t = x - 1; w = t * t * (0.5 - t * (1 / 3.0 - t * 0.25)); u = INV_LN2_H * t; v = t * INV_LN2_L - w * INV_LN2; t1 = (float) (u + v); t2 = v - (t1 - u); } else { long bits = Double.doubleToLongBits(ax); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { ax *= TWO_54; bits = Double.doubleToLongBits(ax); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. ax = Double.longBitsToDouble((bits & 0x000fffffffffffffL) | 0x3ff0000000000000L); boolean k; if (ax < SQRT_1_5) // |x|<sqrt(3/2). k = false; else if (ax < SQRT_3) // |x|<sqrt(3). k = true; else { k = false; ax *= 0.5; exp++; } // Compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5). u = ax - (k ? 1.5 : 1); v = 1 / (ax + (k ? 1.5 : 1)); double s = u * v; double s_h = (float) s; double t_h = (float) (ax + (k ? 1.5 : 1)); double t_l = ax - (t_h - (k ? 1.5 : 1)); double s_l = v * ((u - s_h * t_h) - s_h * t_l); // Compute log(ax). double s2 = s * s; double r = s_l * (s_h + s) + s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6))))); s2 = s_h * s_h; t_h = (float) (3.0 + s2 + r); t_l = r - (t_h - 3.0 - s2); // u+v = s*(1+...). u = s_h * t_h; v = s_l * t_h + t_l * s; // 2/(3log2)*(s+...). double p_h = (float) (u + v); double p_l = v - (p_h - u); double z_h = CP_H * p_h; double z_l = CP_L * p_h + p_l * CP + (k ? DP_L : 0); // log2(ax) = (s+..)*2/(3*log2) = exp + dp_h + z_h + z_l. t = exp; t1 = (float) (z_h + z_l + (k ? DP_H : 0) + t); t2 = z_l - (t1 - t - (k ? DP_H : 0) - z_h); } // Split up y into y1+y2 and compute (y1+y2)*(t1+t2). boolean negative = x < 0 && yisint == 1; double y1 = (float) y; double p_l = (y - y1) * t1 + y * t2; double p_h = y1 * t1; double z = p_l + p_h; if (z >= 1024) // Detect overflow. { if (z > 1024 || p_l + OVT > z - p_h) return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } else if (z <= -1075) // Detect underflow. { if (z < -1075 || p_l <= z - p_h) return negative ? -0.0 : 0; } // Compute 2**(p_h+p_l). int n = round((float) z); p_h -= n; t = (float) (p_l + p_h); u = t * LN2_H; v = (p_l - (t - p_h)) * LN2 + t * LN2_L; z = u + v; w = v - (z - u); t = z * z; t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); double r = (z * t1) / (t1 - 2) - (w + z * w); z = scale(1 - (r - z), n); return negative ? -z : z; }
|
public static double pow(double x, double y) { // Special cases first. if (y == 0) return 1; if (y == 1) return x; if (y == -1) return 1 / x; if (x != x || y != y) return Double.NaN; // When x < 0, yisint tells if y is not an integer (0), even(1), // or odd (2). int yisint = 0; if (x < 0 && floor(y) == y) yisint = (y % 2 == 0) ? 2 : 1; double ax = abs(x); double ay = abs(y); // More special cases, of y. if (ay == Double.POSITIVE_INFINITY) { if (ax == 1) return Double.NaN; if (ax > 1) return y > 0 ? y : 0; return y < 0 ? -y : 0; } if (y == 2) return x * x; if (y == 0.5) return sqrt(x); // More special cases, of x. if (x == 0 || ax == Double.POSITIVE_INFINITY || ax == 1) { if (y < 0) ax = 1 / ax; if (x < 0) { if (x == -1 && yisint == 0) ax = Double.NaN; else if (yisint == 1) ax = -ax; } return ax; } if (x < 0 && yisint == 0) return Double.NaN; // Now we can start! double t; double t1; double t2; double u; double v; double w; if (ay > TWO_31) { if (ay > TWO_64) // Automatic over/underflow. return ((ax < 1) ? y < 0 : y > 0) ? Double.POSITIVE_INFINITY : 0; // Over/underflow if x is not close to one. if (ax < 0.9999995231628418) return y < 0 ? Double.POSITIVE_INFINITY : 0; if (ax >= 1.0000009536743164) return y > 0 ? Double.POSITIVE_INFINITY : 0; // Now |1-x| is <= 2**-20, sufficient to compute // log(x) by x-x^2/2+x^3/3-x^4/4. t = x - 1; w = t * t * (0.5 - t * (1 / 3.0 - t * 0.25)); u = INV_LN2_H * t; v = t * INV_LN2_L - w * INV_LN2; t1 = (float) (u + v); t2 = v - (t1 - u); } else { long bits = Double.doubleToLongBits(ax); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { ax *= TWO_54; bits = Double.doubleToLongBits(ax); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. ax = Double.longBitsToDouble((bits & 0x000fffffffffffffL) | 0x3ff0000000000000L); boolean k; if (ax < SQRT_1_5) // |x|<sqrt(3/2). k = false; else if (ax < SQRT_3) // |x|<sqrt(3). k = true; else { k = false; ax *= 0.5; exp++; } // Compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5). u = ax - (k ? 1.5 : 1); v = 1 / (ax + (k ? 1.5 : 1)); double s = u * v; double s_h = (float) s; double t_h = (float) (ax + (k ? 1.5 : 1)); double t_l = ax - (t_h - (k ? 1.5 : 1)); double s_l = v * ((u - s_h * t_h) - s_h * t_l); // Compute log(ax). double s2 = s * s; double r = s_l * (s_h + s) + s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6))))); s2 = s_h * s_h; t_h = (float) (3.0 + s2 + r); t_l = r - (t_h - 3.0 - s2); // u+v = s*(1+...). u = s_h * t_h; v = s_l * t_h + t_l * s; // 2/(3log2)*(s+...). double p_h = (float) (u + v); double p_l = v - (p_h - u); double z_h = CP_H * p_h; double z_l = CP_L * p_h + p_l * CP + (k ? DP_L : 0); // log2(ax) = (s+..)*2/(3*log2) = exp + dp_h + z_h + z_l. t = exp; t1 = (float) (z_h + z_l + (k ? DP_H : 0) + t); t2 = z_l - (t1 - t - (k ? DP_H : 0) - z_h); } // Split up y into y1+y2 and compute (y1+y2)*(t1+t2). boolean negative = x < 0 && yisint == 1; double y1 = (float) y; double p_l = (y - y1) * t1 + y * t2; double p_h = y1 * t1; double z = p_l + p_h; if (z >= 1024) // Detect overflow. { if (z > 1024 || p_l + OVT > z - p_h) return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } else if (z <= -1075) // Detect underflow. { if (z < -1075 || p_l <= z - p_h) return negative ? -0.0 : 0; } // Compute 2**(p_h+p_l). int n = round((float) z); p_h -= n; t = (float) (p_l + p_h); u = t * LN2_H; v = (p_l - (t - p_h)) * LN2 + t * LN2_L; z = u + v; w = v - (z - u); t = z * z; t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); double r = (z * t1) / (t1 - 2) - (w + z * w); z = scale(1 - (r - z), n); return negative ? -z : z; }
| 2,282
|
public static double pow(double x, double y) { // Special cases first. if (y == 0) return 1; if (y == 1) return x; if (y == -1) return 1 / x; if (x != x || y != y) return Double.NaN; // When x < 0, yisint tells if y is not an integer (0), even(1), // or odd (2). int yisint = 0; if (x < 0 && floor(y) == y) yisint = (y % 2 == 0) ? 2 : 1; double ax = abs(x); double ay = abs(y); // More special cases, of y. if (ay == Double.POSITIVE_INFINITY) { if (ax == 1) return Double.NaN; if (ax > 1) return y > 0 ? y : 0; return y < 0 ? -y : 0; } if (y == 2) return x * x; if (y == 0.5) return sqrt(x); // More special cases, of x. if (x == 0 || ax == Double.POSITIVE_INFINITY || ax == 1) { if (y < 0) ax = 1 / ax; if (x < 0) { if (x == -1 && yisint == 0) ax = Double.NaN; else if (yisint == 1) ax = -ax; } return ax; } if (x < 0 && yisint == 0) return Double.NaN; // Now we can start! double t; double t1; double t2; double u; double v; double w; if (ay > TWO_31) { if (ay > TWO_64) // Automatic over/underflow. return ((ax < 1) ? y < 0 : y > 0) ? Double.POSITIVE_INFINITY : 0; // Over/underflow if x is not close to one. if (ax < 0.9999995231628418) return y < 0 ? Double.POSITIVE_INFINITY : 0; if (ax >= 1.0000009536743164) return y > 0 ? Double.POSITIVE_INFINITY : 0; // Now |1-x| is <= 2**-20, sufficient to compute // log(x) by x-x^2/2+x^3/3-x^4/4. t = x - 1; w = t * t * (0.5 - t * (1 / 3.0 - t * 0.25)); u = INV_LN2_H * t; v = t * INV_LN2_L - w * INV_LN2; t1 = (float) (u + v); t2 = v - (t1 - u); } else { long bits = Double.doubleToLongBits(ax); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { ax *= TWO_54; bits = Double.doubleToLongBits(ax); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. ax = Double.longBitsToDouble((bits & 0x000fffffffffffffL) | 0x3ff0000000000000L); boolean k; if (ax < SQRT_1_5) // |x|<sqrt(3/2). k = false; else if (ax < SQRT_3) // |x|<sqrt(3). k = true; else { k = false; ax *= 0.5; exp++; } // Compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5). u = ax - (k ? 1.5 : 1); v = 1 / (ax + (k ? 1.5 : 1)); double s = u * v; double s_h = (float) s; double t_h = (float) (ax + (k ? 1.5 : 1)); double t_l = ax - (t_h - (k ? 1.5 : 1)); double s_l = v * ((u - s_h * t_h) - s_h * t_l); // Compute log(ax). double s2 = s * s; double r = s_l * (s_h + s) + s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6))))); s2 = s_h * s_h; t_h = (float) (3.0 + s2 + r); t_l = r - (t_h - 3.0 - s2); // u+v = s*(1+...). u = s_h * t_h; v = s_l * t_h + t_l * s; // 2/(3log2)*(s+...). double p_h = (float) (u + v); double p_l = v - (p_h - u); double z_h = CP_H * p_h; double z_l = CP_L * p_h + p_l * CP + (k ? DP_L : 0); // log2(ax) = (s+..)*2/(3*log2) = exp + dp_h + z_h + z_l. t = exp; t1 = (float) (z_h + z_l + (k ? DP_H : 0) + t); t2 = z_l - (t1 - t - (k ? DP_H : 0) - z_h); } // Split up y into y1+y2 and compute (y1+y2)*(t1+t2). boolean negative = x < 0 && yisint == 1; double y1 = (float) y; double p_l = (y - y1) * t1 + y * t2; double p_h = y1 * t1; double z = p_l + p_h; if (z >= 1024) // Detect overflow. { if (z > 1024 || p_l + OVT > z - p_h) return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } else if (z <= -1075) // Detect underflow. { if (z < -1075 || p_l <= z - p_h) return negative ? -0.0 : 0; } // Compute 2**(p_h+p_l). int n = round((float) z); p_h -= n; t = (float) (p_l + p_h); u = t * LN2_H; v = (p_l - (t - p_h)) * LN2 + t * LN2_L; z = u + v; w = v - (z - u); t = z * z; t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); double r = (z * t1) / (t1 - 2) - (w + z * w); z = scale(1 - (r - z), n); return negative ? -z : z; }
|
public static double pow(double x, double y) { // Special cases first. if (y == 0) return 1; if (y == 1) return x; if (y == -1) return 1 / x; if (x != x || y != y) return Double.NaN; // When x < 0, yisint tells if y is not an integer (0), even(1), // or odd (2). int yisint = 0; if (x < 0 && floor(y) == y) yisint = (y % 2 == 0) ? 2 : 1; double ax = abs(x); double ay = abs(y); // More special cases, of y. if (ay == Double.POSITIVE_INFINITY) { if (ax == 1) return Double.NaN; if (ax > 1) return y > 0 ? y : 0; return y < 0 ? -y : 0; } if (y == 2) return x * x; if (y == 0.5) return sqrt(x); // More special cases, of x. if (x == 0 || ax == Double.POSITIVE_INFINITY || ax == 1) { if (y < 0) ax = 1 / ax; if (x < 0) { if (x == -1 && yisint == 0) ax = Double.NaN; else if (yisint == 1) ax = -ax; } return ax; } if (x < 0 && yisint == 0) return Double.NaN; // Now we can start! double t; double t1; double t2; double u; double v; double w; if (ay > TWO_31) { if (ay > TWO_64) // Automatic over/underflow. return ((ax < 1) ? y < 0 : y > 0) ? Double.POSITIVE_INFINITY : 0; // Over/underflow if x is not close to one. if (ax < 0.9999995231628418) return y < 0 ? Double.POSITIVE_INFINITY : 0; if (ax >= 1.0000009536743164) return y > 0 ? Double.POSITIVE_INFINITY : 0; // Now |1-x| is <= 2**-20, sufficient to compute // log(x) by x-x^2/2+x^3/3-x^4/4. t = x - 1; w = t * t * (0.5 - t * (1 / 3.0 - t * 0.25)); u = INV_LN2_H * t; v = t * INV_LN2_L - w * INV_LN2; t1 = (float) (u + v); t2 = v - (t1 - u); } else { long bits = Double.doubleToLongBits(ax); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { ax *= TWO_54; bits = Double.doubleToLongBits(ax); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. ax = Double.longBitsToDouble((bits & 0x000fffffffffffffL) | 0x3ff0000000000000L); boolean k; if (ax < SQRT_1_5) // |x|<sqrt(3/2). k = false; else if (ax < SQRT_3) // |x|<sqrt(3). k = true; else { k = false; ax *= 0.5; exp++; } // Compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5). u = ax - (k ? 1.5 : 1); v = 1 / (ax + (k ? 1.5 : 1)); double s = u * v; double s_h = (float) s; double t_h = (float) (ax + (k ? 1.5 : 1)); double t_l = ax - (t_h - (k ? 1.5 : 1)); double s_l = v * ((u - s_h * t_h) - s_h * t_l); // Compute log(ax). double s2 = s * s; double r = s_l * (s_h + s) + s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6))))); s2 = s_h * s_h; t_h = (float) (3.0 + s2 + r); t_l = r - (t_h - 3.0 - s2); // u+v = s*(1+...). u = s_h * t_h; v = s_l * t_h + t_l * s; // 2/(3log2)*(s+...). double p_h = (float) (u + v); double p_l = v - (p_h - u); double z_h = CP_H * p_h; double z_l = CP_L * p_h + p_l * CP + (k ? DP_L : 0); // log2(ax) = (s+..)*2/(3*log2) = exp + dp_h + z_h + z_l. t = exp; t1 = (float) (z_h + z_l + (k ? DP_H : 0) + t); t2 = z_l - (t1 - t - (k ? DP_H : 0) - z_h); } // Split up y into y1+y2 and compute (y1+y2)*(t1+t2). boolean negative = x < 0 && yisint == 1; double y1 = (float) y; double p_l = (y - y1) * t1 + y * t2; double p_h = y1 * t1; double z = p_l + p_h; if (z >= 1024) // Detect overflow. { if (z > 1024 || p_l + OVT > z - p_h) return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } else if (z <= -1075) // Detect underflow. { if (z < -1075 || p_l <= z - p_h) return negative ? -0.0 : 0; } // Compute 2**(p_h+p_l). int n = round((float) z); p_h -= n; t = (float) (p_l + p_h); u = t * LN2_H; v = (p_l - (t - p_h)) * LN2 + t * LN2_L; z = u + v; w = v - (z - u); t = z * z; t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); double r = (z * t1) / (t1 - 2) - (w + z * w); z = scale(1 - (r - z), n); return negative ? -z : z; }
| 2,283
|
public static synchronized double random() { if (rand == null) rand = new Random(); return rand.nextDouble(); }
|
public static synchronized double random() { if (rand == null) rand = new Random(); return rand.nextDouble(); }
| 2,284
|
private static int remPiOver2(double x, double[] y) { boolean negative = x < 0; x = abs(x); double z; int n; if (x < 3 * PI / 4) // If |x| is small. { z = x - PIO2_1; if ((float) x != (float) (PI / 2)) // 33+53 bit pi is good enough. { y[0] = z - PIO2_1L; y[1] = z - y[0] - PIO2_1L; } else // Near pi/2, use 33+33+53 bit pi. { z -= PIO2_2; y[0] = z - PIO2_2L; y[1] = z - y[0] - PIO2_2L; } n = 1; } else if (x <= TWO_20 * PI / 2) // Medium size. { n = (int) (2 / PI * x + 0.5); z = x - n * PIO2_1; double w = n * PIO2_1L; // First round good to 85 bits. y[0] = z - w; if (n >= 32 || (float) x == (float) (w)) { if (x / y[0] >= TWO_16) // Second iteration, good to 118 bits. { double t = z; w = n * PIO2_2; z = t - w; w = n * PIO2_2L - (t - z - w); y[0] = z - w; if (x / y[0] >= TWO_49) // Third iteration, 151 bits accuracy. { t = z; w = n * PIO2_3; z = t - w; w = n * PIO2_3L - (t - z - w); y[0] = z - w; } } } y[1] = z - y[0] - w; } else { // All other (large) arguments. int e0 = (int) (Double.doubleToLongBits(x) >> 52) - 1046; z = scale(x, -e0); // e0 = ilogb(z) - 23. double[] tx = new double[3]; for (int i = 0; i < 2; i++) { tx[i] = (int) z; z = (z - tx[i]) * TWO_24; } tx[2] = z; int nx = 2; while (tx[nx] == 0) nx--; n = remPiOver2(tx, y, e0, nx); } if (negative) { y[0] = -y[0]; y[1] = -y[1]; return -n; } return n; }
|
private static int remPiOver2(double x, double[] y) { boolean negative = x < 0; x = abs(x); double z; int n; if (x < 3 * PI / 4) // If |x| is small. { z = x - PIO2_1; if ((float) x != (float) (PI / 2)) // 33+53 bit pi is good enough. { y[0] = z - PIO2_1L; y[1] = z - y[0] - PIO2_1L; } else // Near pi/2, use 33+33+53 bit pi. { z -= PIO2_2; y[0] = z - PIO2_2L; y[1] = z - y[0] - PIO2_2L; } n = 1; } else if (x <= TWO_20 * PI / 2) // Medium size. { n = (int) (2 / PI * x + 0.5); z = x - n * PIO2_1; double w = n * PIO2_1L; // First round good to 85 bits. y[0] = z - w; if (n >= 32 || (float) x == (float) (w)) { if (x / y[0] >= TWO_16) // Second iteration, good to 118 bits. { double t = z; w = n * PIO2_2; z = t - w; w = n * PIO2_2L - (t - z - w); y[0] = z - w; if (x / y[0] >= TWO_49) // Third iteration, 151 bits accuracy. { t = z; w = n * PIO2_3; z = t - w; w = n * PIO2_3L - (t - z - w); y[0] = z - w; } } } y[1] = z - y[0] - w; } else { // All other (large) arguments. int e0 = (int) (Double.doubleToLongBits(x) >> 52) - 1046; z = scale(x, -e0); // e0 = ilogb(z) - 23. double[] tx = new double[3]; for (int i = 0; i < 2; i++) { tx[i] = (int) z; z = (z - tx[i]) * TWO_24; } tx[2] = z; int nx = 2; while (tx[nx] == 0) nx--; n = remPiOver2(tx, y, e0, nx); } if (negative) { y[0] = -y[0]; y[1] = -y[1]; return -n; } return n; }
| 2,285
|
private static int remPiOver2(double x, double[] y) { boolean negative = x < 0; x = abs(x); double z; int n; if (x < 3 * PI / 4) // If |x| is small. { z = x - PIO2_1; if ((float) x != (float) (PI / 2)) // 33+53 bit pi is good enough. { y[0] = z - PIO2_1L; y[1] = z - y[0] - PIO2_1L; } else // Near pi/2, use 33+33+53 bit pi. { z -= PIO2_2; y[0] = z - PIO2_2L; y[1] = z - y[0] - PIO2_2L; } n = 1; } else if (x <= TWO_20 * PI / 2) // Medium size. { n = (int) (2 / PI * x + 0.5); z = x - n * PIO2_1; double w = n * PIO2_1L; // First round good to 85 bits. y[0] = z - w; if (n >= 32 || (float) x == (float) (w)) { if (x / y[0] >= TWO_16) // Second iteration, good to 118 bits. { double t = z; w = n * PIO2_2; z = t - w; w = n * PIO2_2L - (t - z - w); y[0] = z - w; if (x / y[0] >= TWO_49) // Third iteration, 151 bits accuracy. { t = z; w = n * PIO2_3; z = t - w; w = n * PIO2_3L - (t - z - w); y[0] = z - w; } } } y[1] = z - y[0] - w; } else { // All other (large) arguments. int e0 = (int) (Double.doubleToLongBits(x) >> 52) - 1046; z = scale(x, -e0); // e0 = ilogb(z) - 23. double[] tx = new double[3]; for (int i = 0; i < 2; i++) { tx[i] = (int) z; z = (z - tx[i]) * TWO_24; } tx[2] = z; int nx = 2; while (tx[nx] == 0) nx--; n = remPiOver2(tx, y, e0, nx); } if (negative) { y[0] = -y[0]; y[1] = -y[1]; return -n; } return n; }
|
private static int remPiOver2(double x, double[] y) { boolean negative = x < 0; x = abs(x); double z; int n; if (x < 3 * PI / 4) // If |x| is small. { z = x - PIO2_1; if ((float) x != (float) (PI / 2)) // 33+53 bit pi is good enough. { y[0] = z - PIO2_1L; y[1] = z - y[0] - PIO2_1L; } else // Near pi/2, use 33+33+53 bit pi. { z -= PIO2_2; y[0] = z - PIO2_2L; y[1] = z - y[0] - PIO2_2L; } n = 1; } else if (x <= TWO_20 * PI / 2) // Medium size. { n = (int) (2 / PI * x + 0.5); z = x - n * PIO2_1; double w = n * PIO2_1L; // First round good to 85 bits. y[0] = z - w; if (n >= 32 || (float) x == (float) (w)) { if (x / y[0] >= TWO_16) // Second iteration, good to 118 bits. { double t = z; w = n * PIO2_2; z = t - w; w = n * PIO2_2L - (t - z - w); y[0] = z - w; if (x / y[0] >= TWO_49) // Third iteration, 151 bits accuracy. { t = z; w = n * PIO2_3; z = t - w; w = n * PIO2_3L - (t - z - w); y[0] = z - w; } } } y[1] = z - y[0] - w; } else { // All other (large) arguments. int e0 = (int) (Double.doubleToLongBits(x) >> 52) - 1046; z = scale(x, -e0); // e0 = ilogb(z) - 23. double[] tx = new double[3]; for (int i = 0; i < 2; i++) { tx[i] = (int) z; z = (z - tx[i]) * TWO_24; } tx[2] = z; int nx = 2; while (tx[nx] == 0) nx--; n = remPiOver2(tx, y, e0, nx); } if (negative) { y[0] = -y[0]; y[1] = -y[1]; return -n; } return n; }
| 2,286
|
private static int remPiOver2(double x, double[] y) { boolean negative = x < 0; x = abs(x); double z; int n; if (x < 3 * PI / 4) // If |x| is small. { z = x - PIO2_1; if ((float) x != (float) (PI / 2)) // 33+53 bit pi is good enough. { y[0] = z - PIO2_1L; y[1] = z - y[0] - PIO2_1L; } else // Near pi/2, use 33+33+53 bit pi. { z -= PIO2_2; y[0] = z - PIO2_2L; y[1] = z - y[0] - PIO2_2L; } n = 1; } else if (x <= TWO_20 * PI / 2) // Medium size. { n = (int) (2 / PI * x + 0.5); z = x - n * PIO2_1; double w = n * PIO2_1L; // First round good to 85 bits. y[0] = z - w; if (n >= 32 || (float) x == (float) (w)) { if (x / y[0] >= TWO_16) // Second iteration, good to 118 bits. { double t = z; w = n * PIO2_2; z = t - w; w = n * PIO2_2L - (t - z - w); y[0] = z - w; if (x / y[0] >= TWO_49) // Third iteration, 151 bits accuracy. { t = z; w = n * PIO2_3; z = t - w; w = n * PIO2_3L - (t - z - w); y[0] = z - w; } } } y[1] = z - y[0] - w; } else { // All other (large) arguments. int e0 = (int) (Double.doubleToLongBits(x) >> 52) - 1046; z = scale(x, -e0); // e0 = ilogb(z) - 23. double[] tx = new double[3]; for (int i = 0; i < 2; i++) { tx[i] = (int) z; z = (z - tx[i]) * TWO_24; } tx[2] = z; int nx = 2; while (tx[nx] == 0) nx--; n = remPiOver2(tx, y, e0, nx); } if (negative) { y[0] = -y[0]; y[1] = -y[1]; return -n; } return n; }
|
private static int remPiOver2(double x, double[] y) { boolean negative = x < 0; x = abs(x); double z; int n; if (x < 3 * PI / 4) // If |x| is small. { z = x - PIO2_1; if ((float) x != (float) (PI / 2)) // 33+53 bit pi is good enough. { y[0] = z - PIO2_1L; y[1] = z - y[0] - PIO2_1L; } else // Near pi/2, use 33+33+53 bit pi. { z -= PIO2_2; y[0] = z - PIO2_2L; y[1] = z - y[0] - PIO2_2L; } n = 1; } else if (x <= TWO_20 * PI / 2) // Medium size. { n = (int) (2 / PI * x + 0.5); z = x - n * PIO2_1; double w = n * PIO2_1L; // First round good to 85 bits. y[0] = z - w; if (n >= 32 || (float) x == (float) (w)) { if (x / y[0] >= TWO_16) // Second iteration, good to 118 bits. { double t = z; w = n * PIO2_2; z = t - w; w = n * PIO2_2L - (t - z - w); y[0] = z - w; if (x / y[0] >= TWO_49) // Third iteration, 151 bits accuracy. { t = z; w = n * PIO2_3; z = t - w; w = n * PIO2_3L - (t - z - w); y[0] = z - w; } } } y[1] = z - y[0] - w; } else { // All other (large) arguments. int e0 = (int) (Double.doubleToLongBits(x) >> 52) - 1046; z = scale(x, -e0); // e0 = ilogb(z) - 23. double[] tx = new double[3]; for (int i = 0; i < 2; i++) { tx[i] = (int) z; z = (z - tx[i]) * TWO_24; } tx[2] = z; int nx = 2; while (tx[nx] == 0) nx--; n = remPiOver2(tx, y, e0, nx); } if (negative) { y[0] = -y[0]; y[1] = -y[1]; return -n; } return n; }
| 2,287
|
private static int remPiOver2(double x, double[] y) { boolean negative = x < 0; x = abs(x); double z; int n; if (x < 3 * PI / 4) // If |x| is small. { z = x - PIO2_1; if ((float) x != (float) (PI / 2)) // 33+53 bit pi is good enough. { y[0] = z - PIO2_1L; y[1] = z - y[0] - PIO2_1L; } else // Near pi/2, use 33+33+53 bit pi. { z -= PIO2_2; y[0] = z - PIO2_2L; y[1] = z - y[0] - PIO2_2L; } n = 1; } else if (x <= TWO_20 * PI / 2) // Medium size. { n = (int) (2 / PI * x + 0.5); z = x - n * PIO2_1; double w = n * PIO2_1L; // First round good to 85 bits. y[0] = z - w; if (n >= 32 || (float) x == (float) (w)) { if (x / y[0] >= TWO_16) // Second iteration, good to 118 bits. { double t = z; w = n * PIO2_2; z = t - w; w = n * PIO2_2L - (t - z - w); y[0] = z - w; if (x / y[0] >= TWO_49) // Third iteration, 151 bits accuracy. { t = z; w = n * PIO2_3; z = t - w; w = n * PIO2_3L - (t - z - w); y[0] = z - w; } } } y[1] = z - y[0] - w; } else { // All other (large) arguments. int e0 = (int) (Double.doubleToLongBits(x) >> 52) - 1046; z = scale(x, -e0); // e0 = ilogb(z) - 23. double[] tx = new double[3]; for (int i = 0; i < 2; i++) { tx[i] = (int) z; z = (z - tx[i]) * TWO_24; } tx[2] = z; int nx = 2; while (tx[nx] == 0) nx--; n = remPiOver2(tx, y, e0, nx); } if (negative) { y[0] = -y[0]; y[1] = -y[1]; return -n; } return n; }
|
private static int remPiOver2(double x, double[] y) { boolean negative = x < 0; x = abs(x); double z; int n; if (x < 3 * PI / 4) // If |x| is small. { z = x - PIO2_1; if ((float) x != (float) (PI / 2)) // 33+53 bit pi is good enough. { y[0] = z - PIO2_1L; y[1] = z - y[0] - PIO2_1L; } else // Near pi/2, use 33+33+53 bit pi. { z -= PIO2_2; y[0] = z - PIO2_2L; y[1] = z - y[0] - PIO2_2L; } n = 1; } else if (x <= TWO_20 * PI / 2) // Medium size. { n = (int) (2 / PI * x + 0.5); z = x - n * PIO2_1; double w = n * PIO2_1L; // First round good to 85 bits. y[0] = z - w; if (n >= 32 || (float) x == (float) (w)) { if (x / y[0] >= TWO_16) // Second iteration, good to 118 bits. { double t = z; w = n * PIO2_2; z = t - w; w = n * PIO2_2L - (t - z - w); y[0] = z - w; if (x / y[0] >= TWO_49) // Third iteration, 151 bits accuracy. { t = z; w = n * PIO2_3; z = t - w; w = n * PIO2_3L - (t - z - w); y[0] = z - w; } } } y[1] = z - y[0] - w; } else { // All other (large) arguments. int e0 = (int) (Double.doubleToLongBits(x) >> 52) - 1046; z = scale(x, -e0); // e0 = ilogb(z) - 23. double[] tx = new double[3]; for (int i = 0; i < 2; i++) { tx[i] = (int) z; z = (z - tx[i]) * TWO_24; } tx[2] = z; int nx = 2; while (tx[nx] == 0) nx--; n = remPiOver2(tx, y, e0, nx); } if (negative) { y[0] = -y[0]; y[1] = -y[1]; return -n; } return n; }
| 2,288
|
private static int remPiOver2(double x, double[] y) { boolean negative = x < 0; x = abs(x); double z; int n; if (x < 3 * PI / 4) // If |x| is small. { z = x - PIO2_1; if ((float) x != (float) (PI / 2)) // 33+53 bit pi is good enough. { y[0] = z - PIO2_1L; y[1] = z - y[0] - PIO2_1L; } else // Near pi/2, use 33+33+53 bit pi. { z -= PIO2_2; y[0] = z - PIO2_2L; y[1] = z - y[0] - PIO2_2L; } n = 1; } else if (x <= TWO_20 * PI / 2) // Medium size. { n = (int) (2 / PI * x + 0.5); z = x - n * PIO2_1; double w = n * PIO2_1L; // First round good to 85 bits. y[0] = z - w; if (n >= 32 || (float) x == (float) (w)) { if (x / y[0] >= TWO_16) // Second iteration, good to 118 bits. { double t = z; w = n * PIO2_2; z = t - w; w = n * PIO2_2L - (t - z - w); y[0] = z - w; if (x / y[0] >= TWO_49) // Third iteration, 151 bits accuracy. { t = z; w = n * PIO2_3; z = t - w; w = n * PIO2_3L - (t - z - w); y[0] = z - w; } } } y[1] = z - y[0] - w; } else { // All other (large) arguments. int e0 = (int) (Double.doubleToLongBits(x) >> 52) - 1046; z = scale(x, -e0); // e0 = ilogb(z) - 23. double[] tx = new double[3]; for (int i = 0; i < 2; i++) { tx[i] = (int) z; z = (z - tx[i]) * TWO_24; } tx[2] = z; int nx = 2; while (tx[nx] == 0) nx--; n = remPiOver2(tx, y, e0, nx); } if (negative) { y[0] = -y[0]; y[1] = -y[1]; return -n; } return n; }
|
private static int remPiOver2(double x, double[] y) { boolean negative = x < 0; x = abs(x); double z; int n; if (x < 3 * PI / 4) // If |x| is small. { z = x - PIO2_1; if ((float) x != (float) (PI / 2)) // 33+53 bit pi is good enough. { y[0] = z - PIO2_1L; y[1] = z - y[0] - PIO2_1L; } else // Near pi/2, use 33+33+53 bit pi. { z -= PIO2_2; y[0] = z - PIO2_2L; y[1] = z - y[0] - PIO2_2L; } n = 1; } else if (x <= TWO_20 * PI / 2) // Medium size. { n = (int) (2 / PI * x + 0.5); z = x - n * PIO2_1; double w = n * PIO2_1L; // First round good to 85 bits. y[0] = z - w; if (n >= 32 || (float) x == (float) (w)) { if (x / y[0] >= TWO_16) // Second iteration, good to 118 bits. { double t = z; w = n * PIO2_2; z = t - w; w = n * PIO2_2L - (t - z - w); y[0] = z - w; if (x / y[0] >= TWO_49) // Third iteration, 151 bits accuracy. { t = z; w = n * PIO2_3; z = t - w; w = n * PIO2_3L - (t - z - w); y[0] = z - w; } } } y[1] = z - y[0] - w; } else { // All other (large) arguments. int e0 = (int) (Double.doubleToLongBits(x) >> 52) - 1046; z = scale(x, -e0); // e0 = ilogb(z) - 23. double[] tx = new double[3]; for (int i = 0; i < 2; i++) { tx[i] = (int) z; z = (z - tx[i]) * TWO_24; } tx[2] = z; int nx = 2; while (tx[nx] == 0) nx--; n = remPiOver2(tx, y, e0, nx); } if (negative) { y[0] = -y[0]; y[1] = -y[1]; return -n; } return n; }
| 2,289
|
private static int remPiOver2(double x, double[] y) { boolean negative = x < 0; x = abs(x); double z; int n; if (x < 3 * PI / 4) // If |x| is small. { z = x - PIO2_1; if ((float) x != (float) (PI / 2)) // 33+53 bit pi is good enough. { y[0] = z - PIO2_1L; y[1] = z - y[0] - PIO2_1L; } else // Near pi/2, use 33+33+53 bit pi. { z -= PIO2_2; y[0] = z - PIO2_2L; y[1] = z - y[0] - PIO2_2L; } n = 1; } else if (x <= TWO_20 * PI / 2) // Medium size. { n = (int) (2 / PI * x + 0.5); z = x - n * PIO2_1; double w = n * PIO2_1L; // First round good to 85 bits. y[0] = z - w; if (n >= 32 || (float) x == (float) (w)) { if (x / y[0] >= TWO_16) // Second iteration, good to 118 bits. { double t = z; w = n * PIO2_2; z = t - w; w = n * PIO2_2L - (t - z - w); y[0] = z - w; if (x / y[0] >= TWO_49) // Third iteration, 151 bits accuracy. { t = z; w = n * PIO2_3; z = t - w; w = n * PIO2_3L - (t - z - w); y[0] = z - w; } } } y[1] = z - y[0] - w; } else { // All other (large) arguments. int e0 = (int) (Double.doubleToLongBits(x) >> 52) - 1046; z = scale(x, -e0); // e0 = ilogb(z) - 23. double[] tx = new double[3]; for (int i = 0; i < 2; i++) { tx[i] = (int) z; z = (z - tx[i]) * TWO_24; } tx[2] = z; int nx = 2; while (tx[nx] == 0) nx--; n = remPiOver2(tx, y, e0, nx); } if (negative) { y[0] = -y[0]; y[1] = -y[1]; return -n; } return n; }
|
private static int remPiOver2(double x, double[] y) { boolean negative = x < 0; x = abs(x); double z; int n; if (x < 3 * PI / 4) // If |x| is small. { z = x - PIO2_1; if ((float) x != (float) (PI / 2)) // 33+53 bit pi is good enough. { y[0] = z - PIO2_1L; y[1] = z - y[0] - PIO2_1L; } else // Near pi/2, use 33+33+53 bit pi. { z -= PIO2_2; y[0] = z - PIO2_2L; y[1] = z - y[0] - PIO2_2L; } n = 1; } else if (x <= TWO_20 * PI / 2) // Medium size. { n = (int) (2 / PI * x + 0.5); z = x - n * PIO2_1; double w = n * PIO2_1L; // First round good to 85 bits. y[0] = z - w; if (n >= 32 || (float) x == (float) (w)) { if (x / y[0] >= TWO_16) // Second iteration, good to 118 bits. { double t = z; w = n * PIO2_2; z = t - w; w = n * PIO2_2L - (t - z - w); y[0] = z - w; if (x / y[0] >= TWO_49) // Third iteration, 151 bits accuracy. { t = z; w = n * PIO2_3; z = t - w; w = n * PIO2_3L - (t - z - w); y[0] = z - w; } } } y[1] = z - y[0] - w; } else { // All other (large) arguments. int e0 = (int) (Double.doubleToLongBits(x) >> 52) - 1046; z = scale(x, -e0); // e0 = ilogb(z) - 23. double[] tx = new double[3]; for (int i = 0; i < 2; i++) { tx[i] = (int) z; z = (z - tx[i]) * TWO_24; } tx[2] = z; int nx = 2; while (tx[nx] == 0) nx--; n = remPiOver2(tx, y, e0, nx); } if (negative) { y[0] = -y[0]; y[1] = -y[1]; return -n; } return n; }
| 2,290
|
private static int remPiOver2(double x, double[] y) { boolean negative = x < 0; x = abs(x); double z; int n; if (x < 3 * PI / 4) // If |x| is small. { z = x - PIO2_1; if ((float) x != (float) (PI / 2)) // 33+53 bit pi is good enough. { y[0] = z - PIO2_1L; y[1] = z - y[0] - PIO2_1L; } else // Near pi/2, use 33+33+53 bit pi. { z -= PIO2_2; y[0] = z - PIO2_2L; y[1] = z - y[0] - PIO2_2L; } n = 1; } else if (x <= TWO_20 * PI / 2) // Medium size. { n = (int) (2 / PI * x + 0.5); z = x - n * PIO2_1; double w = n * PIO2_1L; // First round good to 85 bits. y[0] = z - w; if (n >= 32 || (float) x == (float) (w)) { if (x / y[0] >= TWO_16) // Second iteration, good to 118 bits. { double t = z; w = n * PIO2_2; z = t - w; w = n * PIO2_2L - (t - z - w); y[0] = z - w; if (x / y[0] >= TWO_49) // Third iteration, 151 bits accuracy. { t = z; w = n * PIO2_3; z = t - w; w = n * PIO2_3L - (t - z - w); y[0] = z - w; } } } y[1] = z - y[0] - w; } else { // All other (large) arguments. int e0 = (int) (Double.doubleToLongBits(x) >> 52) - 1046; z = scale(x, -e0); // e0 = ilogb(z) - 23. double[] tx = new double[3]; for (int i = 0; i < 2; i++) { tx[i] = (int) z; z = (z - tx[i]) * TWO_24; } tx[2] = z; int nx = 2; while (tx[nx] == 0) nx--; n = remPiOver2(tx, y, e0, nx); } if (negative) { y[0] = -y[0]; y[1] = -y[1]; return -n; } return n; }
|
private static int remPiOver2(double x, double[] y) { boolean negative = x < 0; x = abs(x); double z; int n; if (x < 3 * PI / 4) // If |x| is small. { z = x - PIO2_1; if ((float) x != (float) (PI / 2)) // 33+53 bit pi is good enough. { y[0] = z - PIO2_1L; y[1] = z - y[0] - PIO2_1L; } else // Near pi/2, use 33+33+53 bit pi. { z -= PIO2_2; y[0] = z - PIO2_2L; y[1] = z - y[0] - PIO2_2L; } n = 1; } else if (x <= TWO_20 * PI / 2) // Medium size. { n = (int) (2 / PI * x + 0.5); z = x - n * PIO2_1; double w = n * PIO2_1L; // First round good to 85 bits. y[0] = z - w; if (n >= 32 || (float) x == (float) (w)) { if (x / y[0] >= TWO_16) // Second iteration, good to 118 bits. { double t = z; w = n * PIO2_2; z = t - w; w = n * PIO2_2L - (t - z - w); y[0] = z - w; if (x / y[0] >= TWO_49) // Third iteration, 151 bits accuracy. { t = z; w = n * PIO2_3; z = t - w; w = n * PIO2_3L - (t - z - w); y[0] = z - w; } } } y[1] = z - y[0] - w; } else { // All other (large) arguments. int e0 = (int) (Double.doubleToLongBits(x) >> 52) - 1046; z = scale(x, -e0); // e0 = ilogb(z) - 23. double[] tx = new double[3]; for (int i = 0; i < 2; i++) { tx[i] = (int) z; z = (z - tx[i]) * TWO_24; } tx[2] = z; int nx = 2; while (tx[nx] == 0) nx--; n = remPiOver2(tx, y, e0, nx); } if (negative) { y[0] = -y[0]; y[1] = -y[1]; return -n; } return n; }
| 2,291
|
public static double rint(double a) { double x = abs(a); if (!(x < TWO_52)) return a; // No fraction bits; includes NaN and infinity. if (x <= 0.5) return 0 * a; // Worry about signed zero. if (x % 2 <= 0.5) return (long) a; // Catch round down to even. return (long) (a + (a < 0 ? -0.5 : 0.5)); // Cast to long truncates. }
|
public static double rint(double a) { double x = abs(a); if (!(x < TWO_52)) return a; // No fraction bits; includes NaN and infinity. if (x <= 0.5) return 0 * a; // Worry about signed zero. if (x % 2 <= 0.5) return (long) a; // Catch round down to even. return (long) (a + (a < 0 ? -0.5 : 0.5)); // Cast to long truncates. }
| 2,292
|
public static double rint(double a) { double x = abs(a); if (!(x < TWO_52)) return a; // No fraction bits; includes NaN and infinity. if (x <= 0.5) return 0 * a; // Worry about signed zero. if (x % 2 <= 0.5) return (long) a; // Catch round down to even. return (long) (a + (a < 0 ? -0.5 : 0.5)); // Cast to long truncates. }
|
public static double rint(double a) { double x = abs(a); if (!(x < TWO_52)) return a; // No fraction bits; includes NaN and infinity. if (x <= 0.5) return 0 * a; // Worry about signed zero. if (x % 2 <= 0.5) return (long) a; // Catch round down to even. return (long) (a + (a < 0 ? -0.5 : 0.5)); // Cast to long truncates. }
| 2,293
|
public static int round(float f) { return (int) floor(f + 0.5f); }
|
public static int round(float f) { return (int) floor(f + 0.5f); }
| 2,294
|
private static double scale(double x, int n) { if (x == 0 || x == Double.NEGATIVE_INFINITY || !(x < Double.POSITIVE_INFINITY) || n == 0) return x; long bits = Double.doubleToLongBits(x); int exp = (int) (bits >> 52) & 0x7ff; if (exp == 0) // Subnormal x. { x *= TWO_54; exp = ((int) (Double.doubleToLongBits(x) >> 52) & 0x7ff) - 54; } exp += n; if (exp > 0x7fe) // Overflow. return Double.POSITIVE_INFINITY * x; if (exp > 0) // Normal. return Double.longBitsToDouble((bits & 0x800fffffffffffffL) | ((long) exp << 52)); if (exp <= -54) return 0 * x; // Underflow. exp += 54; // Subnormal result. x = Double.longBitsToDouble((bits & 0x800fffffffffffffL) | ((long) exp << 52)); return x * (1 / TWO_54); }
|
private static double scale(double x, int n) { if (x == 0 || x == Double.NEGATIVE_INFINITY || !(x < Double.POSITIVE_INFINITY) || n == 0) return x; long bits = Double.doubleToLongBits(x); int exp = (int) (bits >> 52) & 0x7ff; if (exp == 0) // Subnormal x. { x *= TWO_54; exp = ((int) (Double.doubleToLongBits(x) >> 52) & 0x7ff) - 54; } exp += n; if (exp > 0x7fe) // Overflow. return Double.POSITIVE_INFINITY * x; if (exp > 0) // Normal. return Double.longBitsToDouble((bits & 0x800fffffffffffffL) | ((long) exp << 52)); if (exp <= -54) return 0 * x; // Underflow. exp += 54; // Subnormal result. x = Double.longBitsToDouble((bits & 0x800fffffffffffffL) | ((long) exp << 52)); return x * (1 / TWO_54); }
| 2,295
|
private static double scale(double x, int n) { if (x == 0 || x == Double.NEGATIVE_INFINITY || !(x < Double.POSITIVE_INFINITY) || n == 0) return x; long bits = Double.doubleToLongBits(x); int exp = (int) (bits >> 52) & 0x7ff; if (exp == 0) // Subnormal x. { x *= TWO_54; exp = ((int) (Double.doubleToLongBits(x) >> 52) & 0x7ff) - 54; } exp += n; if (exp > 0x7fe) // Overflow. return Double.POSITIVE_INFINITY * x; if (exp > 0) // Normal. return Double.longBitsToDouble((bits & 0x800fffffffffffffL) | ((long) exp << 52)); if (exp <= -54) return 0 * x; // Underflow. exp += 54; // Subnormal result. x = Double.longBitsToDouble((bits & 0x800fffffffffffffL) | ((long) exp << 52)); return x * (1 / TWO_54); }
|
private static double scale(double x, int n) { if (x == 0 || x == Double.NEGATIVE_INFINITY || !(x < Double.POSITIVE_INFINITY) || n == 0) return x; long bits = Double.doubleToLongBits(x); int exp = (int) (bits >> 52) & 0x7ff; if (exp == 0) // Subnormal x. { x *= TWO_54; exp = ((int) (Double.doubleToLongBits(x) >> 52) & 0x7ff) - 54; } exp += n; if (exp > 0x7fe) // Overflow. return Double.POSITIVE_INFINITY * x; if (exp > 0) // Normal. return Double.longBitsToDouble((bits & 0x800fffffffffffffL) | ((long) exp << 52)); if (exp <= -54) return 0 * x; // Underflow. exp += 54; // Subnormal result. x = Double.longBitsToDouble((bits & 0x800fffffffffffffL) | ((long) exp << 52)); return x * (1 / TWO_54); }
| 2,296
|
private static double scale(double x, int n) { if (x == 0 || x == Double.NEGATIVE_INFINITY || !(x < Double.POSITIVE_INFINITY) || n == 0) return x; long bits = Double.doubleToLongBits(x); int exp = (int) (bits >> 52) & 0x7ff; if (exp == 0) // Subnormal x. { x *= TWO_54; exp = ((int) (Double.doubleToLongBits(x) >> 52) & 0x7ff) - 54; } exp += n; if (exp > 0x7fe) // Overflow. return Double.POSITIVE_INFINITY * x; if (exp > 0) // Normal. return Double.longBitsToDouble((bits & 0x800fffffffffffffL) | ((long) exp << 52)); if (exp <= -54) return 0 * x; // Underflow. exp += 54; // Subnormal result. x = Double.longBitsToDouble((bits & 0x800fffffffffffffL) | ((long) exp << 52)); return x * (1 / TWO_54); }
|
private static double scale(double x, int n) { if (x == 0 || x == Double.NEGATIVE_INFINITY || !(x < Double.POSITIVE_INFINITY) || n == 0) return x; long bits = Double.doubleToLongBits(x); int exp = (int) (bits >> 52) & 0x7ff; if (exp == 0) // Subnormal x. { x *= TWO_54; exp = ((int) (Double.doubleToLongBits(x) >> 52) & 0x7ff) - 54; } exp += n; if (exp > 0x7fe) // Overflow. return Double.POSITIVE_INFINITY * x; if (exp > 0) // Normal. return Double.longBitsToDouble((bits & 0x800fffffffffffffL) | ((long) exp << 52)); if (exp <= -54) return 0 * x; // Underflow. exp += 54; // Subnormal result. x = Double.longBitsToDouble((bits & 0x800fffffffffffffL) | ((long) exp << 52)); return x * (1 / TWO_54); }
| 2,297
|
public static double sin(double a) { if (a == Double.NEGATIVE_INFINITY || !(a < Double.POSITIVE_INFINITY)) return Double.NaN; if (abs(a) <= PI / 4) return sin(a, 0); // Argument reduction needed. double[] y = new double[2]; int n = remPiOver2(a, y); switch (n & 3) { case 0 : return sin(y[0], y[1]); case 1 : return cos(y[0], y[1]); case 2 : return -sin(y[0], y[1]); default : return -cos(y[0], y[1]); } }
|
public static double sin(double a) { if (a == Double.NEGATIVE_INFINITY || !(a < Double.POSITIVE_INFINITY)) return Double.NaN; if (abs(a) <= PI / 4) return sin(a, 0); // Argument reduction needed. double[] y = new double[2]; int n = remPiOver2(a, y); switch (n & 3) { case 0 : return sin(y[0], y[1]); case 1 : return cos(y[0], y[1]); case 2 : return -sin(y[0], y[1]); default : return -cos(y[0], y[1]); } }
| 2,298
|
public static double sin(double a) { if (a == Double.NEGATIVE_INFINITY || !(a < Double.POSITIVE_INFINITY)) return Double.NaN; if (abs(a) <= PI / 4) return sin(a, 0); // Argument reduction needed. double[] y = new double[2]; int n = remPiOver2(a, y); switch (n & 3) { case 0 : return sin(y[0], y[1]); case 1 : return cos(y[0], y[1]); case 2 : return -sin(y[0], y[1]); default : return -cos(y[0], y[1]); } }
|
public static double sin(double a) { if (a == Double.NEGATIVE_INFINITY || !(a < Double.POSITIVE_INFINITY)) return Double.NaN; if (abs(a) <= PI / 4) return sin(a, 0); // Argument reduction needed. double[] y = new double[2]; int n = remPiOver2(a, y); switch (n & 3) { case 0 : return sin(y[0], y[1]); case 1 : return cos(y[0], y[1]); case 2 : return -sin(y[0], y[1]); default : return -cos(y[0], y[1]); } }
| 2,299
|
public static double sin(double a) { if (a == Double.NEGATIVE_INFINITY || !(a < Double.POSITIVE_INFINITY)) return Double.NaN; if (abs(a) <= PI / 4) return sin(a, 0); // Argument reduction needed. double[] y = new double[2]; int n = remPiOver2(a, y); switch (n & 3) { case 0 : return sin(y[0], y[1]); case 1 : return cos(y[0], y[1]); case 2 : return -sin(y[0], y[1]); default : return -cos(y[0], y[1]); } }
|
public static double sin(double a) { if (a == Double.NEGATIVE_INFINITY || !(a < Double.POSITIVE_INFINITY)) return Double.NaN; if (abs(a) <= PI / 4) return sin(a, 0); // Argument reduction needed. double[] y = new double[2]; int n = remPiOver2(a, y); switch (n & 3) { case 0 : return sin(y[0], y[1]); case 1 : return cos(y[0], y[1]); case 2 : return -sin(y[0], y[1]); default : return -cos(y[0], y[1]); } }
| 2,300
|
public static double sin(double a) { if (a == Double.NEGATIVE_INFINITY || !(a < Double.POSITIVE_INFINITY)) return Double.NaN; if (abs(a) <= PI / 4) return sin(a, 0); // Argument reduction needed. double[] y = new double[2]; int n = remPiOver2(a, y); switch (n & 3) { case 0 : return sin(y[0], y[1]); case 1 : return cos(y[0], y[1]); case 2 : return -sin(y[0], y[1]); default : return -cos(y[0], y[1]); } }
|
public static double sin(double a) { if (a == Double.NEGATIVE_INFINITY || !(a < Double.POSITIVE_INFINITY)) return Double.NaN; if (abs(a) <= PI / 4) return sin(a, 0); // Argument reduction needed. double[] y = new double[2]; int n = remPiOver2(a, y); switch (n & 3) { case 0 : return sin(y[0], y[1]); case 1 : return cos(y[0], y[1]); case 2 : return -sin(y[0], y[1]); default : return -cos(y[0], y[1]); } }
| 2,301
|
public static double sin(double a) { if (a == Double.NEGATIVE_INFINITY || !(a < Double.POSITIVE_INFINITY)) return Double.NaN; if (abs(a) <= PI / 4) return sin(a, 0); // Argument reduction needed. double[] y = new double[2]; int n = remPiOver2(a, y); switch (n & 3) { case 0 : return sin(y[0], y[1]); case 1 : return cos(y[0], y[1]); case 2 : return -sin(y[0], y[1]); default : return -cos(y[0], y[1]); } }
|
public static double sin(double a) { if (a == Double.NEGATIVE_INFINITY || !(a < Double.POSITIVE_INFINITY)) return Double.NaN; if (abs(a) <= PI / 4) return sin(a, 0); // Argument reduction needed. double[] y = new double[2]; int n = remPiOver2(a, y); switch (n & 3) { case 0 : return sin(y[0], y[1]); case 1 : return cos(y[0], y[1]); case 2 : return -sin(y[0], y[1]); default : return -cos(y[0], y[1]); } }
| 2,302
|
public static double sqrt(double x) { if (x < 0) return Double.NaN; if (x == 0 || !(x < Double.POSITIVE_INFINITY)) return x; // Normalize x. long bits = Double.doubleToLongBits(x); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { x *= TWO_54; bits = Double.doubleToLongBits(x); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. bits = (bits & 0x000fffffffffffffL) | 0x0010000000000000L; if ((exp & 1) == 1) // Odd exp, double x to make it even. bits <<= 1; exp >>= 1; // Generate sqrt(x) bit by bit. bits <<= 1; long q = 0; long s = 0; long r = 0x0020000000000000L; // Move r right to left. while (r != 0) { long t = s + r; if (t <= bits) { s = t + r; bits -= t; q += r; } bits <<= 1; r >>= 1; } // Use floating add to round correctly. if (bits != 0) q += q & 1; return Double.longBitsToDouble((q >> 1) + ((exp + 1022L) << 52)); }
|
public static double sqrt(double x) { if (x < 0) return Double.NaN; if (x == 0 || !(x < Double.POSITIVE_INFINITY)) return x; // Normalize x. long bits = Double.doubleToLongBits(x); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { x *= TWO_54; bits = Double.doubleToLongBits(x); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. bits = (bits & 0x000fffffffffffffL) | 0x0010000000000000L; if ((exp & 1) == 1) // Odd exp, double x to make it even. bits <<= 1; exp >>= 1; // Generate sqrt(x) bit by bit. bits <<= 1; long q = 0; long s = 0; long r = 0x0020000000000000L; // Move r right to left. while (r != 0) { long t = s + r; if (t <= bits) { s = t + r; bits -= t; q += r; } bits <<= 1; r >>= 1; } // Use floating add to round correctly. if (bits != 0) q += q & 1; return Double.longBitsToDouble((q >> 1) + ((exp + 1022L) << 52)); }
| 2,303
|
public static double sqrt(double x) { if (x < 0) return Double.NaN; if (x == 0 || !(x < Double.POSITIVE_INFINITY)) return x; // Normalize x. long bits = Double.doubleToLongBits(x); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { x *= TWO_54; bits = Double.doubleToLongBits(x); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. bits = (bits & 0x000fffffffffffffL) | 0x0010000000000000L; if ((exp & 1) == 1) // Odd exp, double x to make it even. bits <<= 1; exp >>= 1; // Generate sqrt(x) bit by bit. bits <<= 1; long q = 0; long s = 0; long r = 0x0020000000000000L; // Move r right to left. while (r != 0) { long t = s + r; if (t <= bits) { s = t + r; bits -= t; q += r; } bits <<= 1; r >>= 1; } // Use floating add to round correctly. if (bits != 0) q += q & 1; return Double.longBitsToDouble((q >> 1) + ((exp + 1022L) << 52)); }
|
public static double sqrt(double x) { if (x < 0) return Double.NaN; if (x == 0 || !(x < Double.POSITIVE_INFINITY)) return x; // Normalize x. long bits = Double.doubleToLongBits(x); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { x *= TWO_54; bits = Double.doubleToLongBits(x); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. bits = (bits & 0x000fffffffffffffL) | 0x0010000000000000L; if ((exp & 1) == 1) // Odd exp, double x to make it even. bits <<= 1; exp >>= 1; // Generate sqrt(x) bit by bit. bits <<= 1; long q = 0; long s = 0; long r = 0x0020000000000000L; // Move r right to left. while (r != 0) { long t = s + r; if (t <= bits) { s = t + r; bits -= t; q += r; } bits <<= 1; r >>= 1; } // Use floating add to round correctly. if (bits != 0) q += q & 1; return Double.longBitsToDouble((q >> 1) + ((exp + 1022L) << 52)); }
| 2,304
|
public static double sqrt(double x) { if (x < 0) return Double.NaN; if (x == 0 || !(x < Double.POSITIVE_INFINITY)) return x; // Normalize x. long bits = Double.doubleToLongBits(x); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { x *= TWO_54; bits = Double.doubleToLongBits(x); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. bits = (bits & 0x000fffffffffffffL) | 0x0010000000000000L; if ((exp & 1) == 1) // Odd exp, double x to make it even. bits <<= 1; exp >>= 1; // Generate sqrt(x) bit by bit. bits <<= 1; long q = 0; long s = 0; long r = 0x0020000000000000L; // Move r right to left. while (r != 0) { long t = s + r; if (t <= bits) { s = t + r; bits -= t; q += r; } bits <<= 1; r >>= 1; } // Use floating add to round correctly. if (bits != 0) q += q & 1; return Double.longBitsToDouble((q >> 1) + ((exp + 1022L) << 52)); }
|
public static double sqrt(double x) { if (x < 0) return Double.NaN; if (x == 0 || !(x < Double.POSITIVE_INFINITY)) return x; // Normalize x. long bits = Double.doubleToLongBits(x); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { x *= TWO_54; bits = Double.doubleToLongBits(x); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. bits = (bits & 0x000fffffffffffffL) | 0x0010000000000000L; if ((exp & 1) == 1) // Odd exp, double x to make it even. bits <<= 1; exp >>= 1; // Generate sqrt(x) bit by bit. bits <<= 1; long q = 0; long s = 0; long r = 0x0020000000000000L; // Move r right to left. while (r != 0) { long t = s + r; if (t <= bits) { s = t + r; bits -= t; q += r; } bits <<= 1; r >>= 1; } // Use floating add to round correctly. if (bits != 0) q += q & 1; return Double.longBitsToDouble((q >> 1) + ((exp + 1022L) << 52)); }
| 2,305
|
public static double sqrt(double x) { if (x < 0) return Double.NaN; if (x == 0 || !(x < Double.POSITIVE_INFINITY)) return x; // Normalize x. long bits = Double.doubleToLongBits(x); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { x *= TWO_54; bits = Double.doubleToLongBits(x); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. bits = (bits & 0x000fffffffffffffL) | 0x0010000000000000L; if ((exp & 1) == 1) // Odd exp, double x to make it even. bits <<= 1; exp >>= 1; // Generate sqrt(x) bit by bit. bits <<= 1; long q = 0; long s = 0; long r = 0x0020000000000000L; // Move r right to left. while (r != 0) { long t = s + r; if (t <= bits) { s = t + r; bits -= t; q += r; } bits <<= 1; r >>= 1; } // Use floating add to round correctly. if (bits != 0) q += q & 1; return Double.longBitsToDouble((q >> 1) + ((exp + 1022L) << 52)); }
|
public static double sqrt(double x) { if (x < 0) return Double.NaN; if (x == 0 || !(x < Double.POSITIVE_INFINITY)) return x; // Normalize x. long bits = Double.doubleToLongBits(x); int exp = (int) (bits >> 52); if (exp == 0) // Subnormal x. { x *= TWO_54; bits = Double.doubleToLongBits(x); exp = (int) (bits >> 52) - 54; } exp -= 1023; // Unbias exponent. bits = (bits & 0x000fffffffffffffL) | 0x0010000000000000L; if ((exp & 1) == 1) // Odd exp, double x to make it even. bits <<= 1; exp >>= 1; // Generate sqrt(x) bit by bit. bits <<= 1; long q = 0; long s = 0; long r = 0x0020000000000000L; // Move r right to left. while (r != 0) { long t = s + r; if (t <= bits) { s = t + r; bits -= t; q += r; } bits <<= 1; r >>= 1; } // Use floating add to round correctly. if (bits != 0) q += q & 1; return Double.longBitsToDouble((q >> 1) + ((exp + 1022L) << 52)); }
| 2,306
|
public static double tan(double a) { if (a == Double.NEGATIVE_INFINITY || !(a < Double.POSITIVE_INFINITY)) return Double.NaN; if (abs(a) <= PI / 4) return tan(a, 0, false); // Argument reduction needed. double[] y = new double[2]; int n = remPiOver2(a, y); return tan(y[0], y[1], (n & 1) == 1); }
|
public static double tan(double a) { if (a == Double.NEGATIVE_INFINITY || !(a < Double.POSITIVE_INFINITY)) return Double.NaN; if (abs(a) <= PI / 4) return tan(a, 0, false); // Argument reduction needed. double[] y = new double[2]; int n = remPiOver2(a, y); return tan(y[0], y[1], (n & 1) == 1); }
| 2,307
|
public static double toDegrees(double rads) { return rads * (180 / PI); }
|
public static double toDegrees(double rads) { return rads * (180 / PI); }
| 2,308
|
public static double toRadians(double degrees) { return degrees * (PI / 180); }
|
public static double toRadians(double degrees) { return degrees * (PI / 180); }
| 2,309
|
String generateName () { return "frame" + getUniqueLong (); }
|
String generateName() { return "frame" + getUniqueLong (); }
| 2,310
|
String generateName () { return "frame" + getUniqueLong (); }
|
String generateName () { return "frame" + getUniqueLong(); }
| 2,311
|
getCursorType(){ return(getCursor().getType());}
|
getCursorType(){ return(getCursor().getType());}
| 2,312
|
public int getExtendedState () { return state; }
|
public int getExtendedState() { return state; }
| 2,313
|
public static Frame[] getFrames(){ int n = 0; synchronized (weakFrames) { Iterator i = weakFrames.iterator(); while (i.hasNext()) { WeakReference wr = (WeakReference) i.next(); if (wr.get() != null) ++n; } if (n == 0) return new Frame[0]; else { Frame[] frames = new Frame[n]; n = 0; i = weakFrames.iterator(); while (i.hasNext()) { WeakReference wr = (WeakReference) i.next(); if (wr.get() != null) frames[n++] = (Frame) wr.get(); } return frames; } }}
|
public static Frame[] getFrames(){ int n = 0; synchronized (weakFrames) { Iterator i = weakFrames.iterator(); while (i.hasNext()) { WeakReference wr = (WeakReference) i.next(); if (wr.get() != null) ++n; } if (n == 0) return new Frame[0]; else { Frame[] frames = new Frame[n]; n = 0; i = weakFrames.iterator(); while (i.hasNext()) { WeakReference wr = (WeakReference) i.next(); if (wr.get() != null) frames[n++] = (Frame) wr.get(); } return frames; } }}
| 2,314
|
public static Frame[] getFrames(){ int n = 0; synchronized (weakFrames) { Iterator i = weakFrames.iterator(); while (i.hasNext()) { WeakReference wr = (WeakReference) i.next(); if (wr.get() != null) ++n; } if (n == 0) return new Frame[0]; else { Frame[] frames = new Frame[n]; n = 0; i = weakFrames.iterator(); while (i.hasNext()) { WeakReference wr = (WeakReference) i.next(); if (wr.get() != null) frames[n++] = (Frame) wr.get(); } return frames; } }}
|
public static Frame[] getFrames(){ int n = 0; synchronized (weakFrames) { Iterator i = weakFrames.iterator(); while (i.hasNext()) { WeakReference wr = (WeakReference) i.next(); if (wr.get() != null) ++n; } if (n == 0) return new Frame[0]; else { Frame[] frames = new Frame[n]; n = 0; i = weakFrames.iterator(); while (i.hasNext()) { WeakReference wr = (WeakReference) i.next(); if (wr.get() != null) frames[n++] = (Frame) wr.get(); } return frames; } }}
| 2,315
|
public Rectangle getMaximizedBounds () { return maximizedBounds; }
|
public Rectangle getMaximizedBounds() { return maximizedBounds; }
| 2,316
|
private static synchronized long getUniqueLong () { return next_frame_number++; }
|
private static synchronized long getUniqueLong() { return next_frame_number++; }
| 2,317
|
public boolean isUndecorated () { return undecorated; }
|
public boolean isUndecorated() { return undecorated; }
| 2,318
|
private static void noteFrame(Frame f){ weakFrames.add(new WeakReference(f));}
|
private static void noteFrame(Frame f){ weakFrames.add(new WeakReference(f));}
| 2,319
|
private static void noteFrame(Frame f){ weakFrames.add(new WeakReference(f));}
|
private static void noteFrame(Frame f){ weakFrames.add(new WeakReference(f));}
| 2,320
|
remove(MenuComponent menu){ menuBar.remove(menu);}
|
remove(MenuComponent menu){ menuBar.remove(menu);}
| 2,321
|
remove(MenuComponent menu){ menuBar.remove(menu);}
|
remove(MenuComponent menu){ menuBar.remove(menu);}
| 2,322
|
public void removeNotify(){ if (menuBar != null) menuBar.removeNotify(); super.removeNotify();}
|
public void removeNotify(){ if (menuBar != null) menuBar.removeNotify(); super.removeNotify();}
| 2,323
|
public void removeNotify(){ if (menuBar != null) menuBar.removeNotify(); super.removeNotify();}
|
public void removeNotify(){ if (menuBar != null) menuBar.removeNotify(); super.removeNotify();}
| 2,324
|
setCursor(int type){ setCursor(new Cursor(type));}
|
setCursor(int type){ setCursor(new Cursor(type));}
| 2,325
|
setCursor(int type){ setCursor(new Cursor(type));}
|
setCursor(int type){ setCursor(new Cursor(type));}
| 2,326
|
public void setExtendedState (int state) { this.state = state; }
|
public void setExtendedState(int state) { this.state = state; }
| 2,327
|
public void setMaximizedBounds (Rectangle maximizedBounds) { this.maximizedBounds = maximizedBounds; }
|
public void setMaximizedBounds(Rectangle maximizedBounds) { this.maximizedBounds = maximizedBounds; }
| 2,328
|
setMenuBar(MenuBar menuBar){ if (peer != null) { if (this.menuBar != null) this.menuBar.removeNotify(); if (menuBar != null) menuBar.addNotify(); invalidateTree (); ((FramePeer) peer).setMenuBar(menuBar); } this.menuBar = menuBar;}
|
setMenuBar(MenuBar menuBar){ if (peer != null) { if (this.menuBar != null) this.menuBar.removeNotify(); if (menuBar != null) menuBar.addNotify(); invalidateTree (); ((FramePeer) peer).setMenuBar(menuBar); } this.menuBar = menuBar;}
| 2,329
|
setMenuBar(MenuBar menuBar){ if (peer != null) { if (this.menuBar != null) this.menuBar.removeNotify(); if (menuBar != null) menuBar.addNotify(); invalidateTree (); ((FramePeer) peer).setMenuBar(menuBar); } this.menuBar = menuBar;}
|
setMenuBar(MenuBar menuBar){ if (peer != null) { if (this.menuBar != null) this.menuBar.removeNotify(); if (menuBar != null) menuBar.addNotify(); invalidateTree (); ((FramePeer) peer).setMenuBar(menuBar); } this.menuBar = menuBar;}
| 2,330
|
setResizable(boolean resizable){ this.resizable = resizable; if (peer != null) ((FramePeer) peer).setResizable(resizable);}
|
setResizable(boolean resizable){ this.resizable = resizable; if (peer != null) ((FramePeer) peer).setResizable(resizable);}
| 2,331
|
setResizable(boolean resizable){ this.resizable = resizable; if (peer != null) ((FramePeer) peer).setResizable(resizable);}
|
setResizable(boolean resizable){ this.resizable = resizable; if (peer != null) ((FramePeer) peer).setResizable(resizable);}
| 2,332
|
public void setState (int state) { int current_state = getExtendedState (); if (state == NORMAL && (current_state & ICONIFIED) != 0) setExtendedState (current_state | ICONIFIED); if (state == ICONIFIED && (current_state & ~ICONIFIED) == 0) setExtendedState (current_state & ~ICONIFIED); }
|
public void setState(int state) { int current_state = getExtendedState (); if (state == NORMAL && (current_state & ICONIFIED) != 0) setExtendedState (current_state | ICONIFIED); if (state == ICONIFIED && (current_state & ~ICONIFIED) == 0) setExtendedState (current_state & ~ICONIFIED); }
| 2,333
|
public void setState (int state) { int current_state = getExtendedState (); if (state == NORMAL && (current_state & ICONIFIED) != 0) setExtendedState (current_state | ICONIFIED); if (state == ICONIFIED && (current_state & ~ICONIFIED) == 0) setExtendedState (current_state & ~ICONIFIED); }
|
public void setState (int state) { int current_state = getExtendedState (); if (state == NORMAL && (current_state & ICONIFIED) != 0) setExtendedState(current_state | ICONIFIED); if (state == ICONIFIED && (current_state & ~ICONIFIED) == 0) setExtendedState (current_state & ~ICONIFIED); }
| 2,334
|
public void setState (int state) { int current_state = getExtendedState (); if (state == NORMAL && (current_state & ICONIFIED) != 0) setExtendedState (current_state | ICONIFIED); if (state == ICONIFIED && (current_state & ~ICONIFIED) == 0) setExtendedState (current_state & ~ICONIFIED); }
|
public void setState (int state) { int current_state = getExtendedState (); if (state == NORMAL && (current_state & ICONIFIED) != 0) setExtendedState (current_state | ICONIFIED); if (state == ICONIFIED && (current_state & ~ICONIFIED) == 0) setExtendedState(current_state & ~ICONIFIED); }
| 2,335
|
public void setUndecorated (boolean undecorated) { if (isDisplayable ()) throw new IllegalComponentStateException (); this.undecorated = undecorated; }
|
public void setUndecorated(boolean undecorated) { if (isDisplayable ()) throw new IllegalComponentStateException (); this.undecorated = undecorated; }
| 2,336
|
public void setUndecorated (boolean undecorated) { if (isDisplayable ()) throw new IllegalComponentStateException (); this.undecorated = undecorated; }
|
public void setUndecorated (boolean undecorated) { if (isDisplayable ()) throw new IllegalComponentStateException (); this.undecorated = undecorated; }
| 2,337
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.