Javolution 6.0.0 java
javolution.lang.MathLib Class Reference
Collaboration diagram for javolution.lang.MathLib:
[legend]

Static Public Member Functions

static int bitLength (int i)
 
static int bitLength (long l)
 
static int bitCount (long longValue)
 
static int numberOfLeadingZeros (long longValue)
 
static int numberOfTrailingZeros (long longValue)
 
static int digitLength (int i)
 
static int digitLength (long l)
 
static double toDoublePow2 (long m, int n)
 
static double toDoublePow10 (long m, int n)
 
static long toLongPow2 (double d, int n)
 
static long toLongPow10 (double d, int n)
 
static int floorLog2 (double d)
 
static int floorLog10 (double d)
 
static double toRadians (double degrees)
 
static double toDegrees (double radians)
 
static double sqrt (double x)
 
static double rem (double x, double y)
 
static double ceil (double x)
 
static double floor (double x)
 
static double sin (double radians)
 
static double cos (double radians)
 
static double tan (double radians)
 
static double asin (double x)
 
static double acos (double x)
 
static double atan (double x)
 
static double atan2 (double y, double x)
 
static double sinh (double x)
 
static double cosh (double x)
 
static double tanh (double x)
 
static double exp (double x)
 
static double log (double x)
 
static double log10 (double x)
 
static double pow (double x, double y)
 
static int round (float f)
 
static long round (double d)
 
static int abs (int i)
 
static long abs (long l)
 
static float abs (float f)
 
static double abs (double d)
 
static int max (int x, int y)
 
static long max (long x, long y)
 
static float max (float x, float y)
 
static double max (double x, double y)
 
static int min (int x, int y)
 
static long min (long x, long y)
 
static float min (float x, float y)
 
static double min (double x, double y)
 

Static Public Attributes

static final double E = 2.71828182845904523536028747135266
 
static final double PI = 3.1415926535897932384626433832795
 
static final double HALF_PI = 1.5707963267948966192313216916398
 
static final double TWO_PI = 6.283185307179586476925286766559
 
static final double FOUR_PI = 12.566370614359172953850573533118
 
static final double PI_SQUARE = 9.8696044010893586188344909998762
 
static final double LOG2 = 0.69314718055994530941723212145818
 
static final double LOG10 = 2.3025850929940456840179914546844
 
static final double SQRT2 = 1.4142135623730950488016887242097
 
static final double NaN = 0.0 / 0.0
 
static final double Infinity = 1.0 / 0.0
 

Static Package Functions

static double _atan (double x)
 
static double _ieee754_log (double x)
 
static double _ieee754_exp (double x)
 

Static Package Attributes

static final double atanhi []
 
static final double atanlo []
 
static final double aT []
 
static final double one = 1.0
 
static final double huge = 1.0e300
 
static final double ln2_hi = 6.93147180369123816490e-01
 
static final double ln2_lo = 1.90821492927058770002e-10
 
static final double two54 = 1.80143985094819840000e+16
 
static final double Lg1 = 6.666666666666735130e-01
 
static final double Lg2 = 3.999999999940941908e-01
 
static final double Lg3 = 2.857142874366239149e-01
 
static final double Lg4 = 2.222219843214978396e-01
 
static final double Lg5 = 1.818357216161805012e-01
 
static final double Lg6 = 1.531383769920937332e-01
 
static final double Lg7 = 1.479819860511658591e-01
 
static final double zero = 0.0
 
static final double halF [] = { 0.5, -0.5, }
 
static final double twom1000 = 9.33263618503218878990e-302
 
static final double o_threshold = 7.09782712893383973096e+02
 
static final double u_threshold = -7.45133219101941108420e+02
 
static final double ln2HI []
 
static final double ln2LO []
 
static final double invln2 = 1.44269504088896338700e+00
 
static final double P1 = 1.66666666666666019037e-01
 
static final double P2 = -2.77777777770155933842e-03
 
static final double P3 = 6.61375632143793436117e-05
 
static final double P4 = -1.65339022054652515390e-06
 
static final double P5 = 4.13813679705723846039e-08
 

Private Member Functions

 MathLib ()
 

Static Private Attributes

static final byte[] BIT_LENGTH
 
static final long MASK_63 = 0x7FFFFFFFFFFFFFFFL
 
static final long MASK_32 = 0xFFFFFFFFL
 
static final int[] POW5_INT
 
static final double LOG2_DIV_LOG10 = 0.3010299956639811952137388947
 
static double INV_LOG10 = 0.43429448190325182765112891891661
 

Detailed Description

An utility class providing a Realtime implementation of the math library.

Author
Jean-Marie Dautelle
Version
4.2, January 6, 2007

Definition at line 20 of file MathLib.java.

Constructor & Destructor Documentation

◆ MathLib()

javolution.lang.MathLib.MathLib ( )
private

Default constructor.

Definition at line 25 of file MathLib.java.

25 {}

Member Function Documentation

◆ _atan()

static double javolution.lang.MathLib._atan ( double  x)
staticpackage

Definition at line 1109 of file MathLib.java.

1109  {
1110  double w, s1, s2, z;
1111  int ix, hx, id;
1112  long xBits = Double.doubleToLongBits(x);
1113  int __HIx = (int) (xBits >> 32);
1114  int __LOx = (int) xBits;
1115 
1116  hx = __HIx;
1117  ix = hx & 0x7fffffff;
1118  if (ix >= 0x44100000) { // if |x| >= 2^66
1119  if (ix > 0x7ff00000 || (ix == 0x7ff00000 && (__LOx != 0)))
1120  return x + x; // NaN
1121  if (hx > 0)
1122  return atanhi[3] + atanlo[3];
1123  else
1124  return -atanhi[3] - atanlo[3];
1125  }
1126  if (ix < 0x3fdc0000) { // |x| < 0.4375
1127  if (ix < 0x3e200000) // |x| < 2^-29
1128  if (huge + x > one)
1129  return x;
1130  id = -1;
1131  } else {
1132  x = MathLib.abs(x);
1133  if (ix < 0x3ff30000) // |x| < 1.1875
1134  if (ix < 0x3fe60000) { // 7/16 <=|x|<11/16
1135  id = 0;
1136  x = (2.0 * x - one) / (2.0 + x);
1137  } else { // 11/16<=|x|< 19/16
1138  id = 1;
1139  x = (x - one) / (x + one);
1140  }
1141  else if (ix < 0x40038000) { // |x| < 2.4375
1142  id = 2;
1143  x = (x - 1.5) / (one + 1.5 * x);
1144  } else { // 2.4375 <= |x| < 2^66
1145  id = 3;
1146  x = -1.0 / x;
1147  }
1148  }
1149  // end of argument reduction
1150  z = x * x;
1151  w = z * z;
1152  // break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly
1153  s1 = z
1154  * (aT[0] + w
1155  * (aT[2] + w
1156  * (aT[4] + w
1157  * (aT[6] + w * (aT[8] + w * aT[10])))));
1158  s2 = w * (aT[1] + w * (aT[3] + w * (aT[5] + w * (aT[7] + w * aT[9]))));
1159  if (id < 0)
1160  return x - x * (s1 + s2);
1161  else {
1162  z = atanhi[id] - ((x * (s1 + s2) - atanlo[id]) - x);
1163  return (hx < 0) ? -z : z;
1164  }
1165  }

References javolution.lang.MathLib.abs(), javolution.lang.MathLib.aT, javolution.lang.MathLib.atanhi, javolution.lang.MathLib.atanlo, javolution.lang.MathLib.huge, and javolution.lang.MathLib.one.

Referenced by javolution.lang.MathLib.atan().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _ieee754_exp()

static double javolution.lang.MathLib._ieee754_exp ( double  x)
staticpackage

Definition at line 1404 of file MathLib.java.

1405  {
1406  double y, hi = 0, lo = 0, c, t;
1407  int k = 0, xsb;
1408  int hx; // Unsigned.
1409  long xBits = Double.doubleToLongBits(x);
1410  int __HIx = (int) (xBits >> 32);
1411  int __LOx = (int) xBits;
1412 
1413  hx = __HIx; // high word of x
1414  xsb = (hx >> 31) & 1; // sign bit of x
1415  hx &= 0x7fffffff; // high word of |x|
1416 
1417  // filter out non-finite argument
1418  if (hx >= 0x40862E42) { // if |x|>=709.78...
1419  if (hx >= 0x7ff00000)
1420  if (((hx & 0xfffff) | __LOx) != 0)
1421  return x + x; // NaN
1422  else
1423  return (xsb == 0) ? x : 0.0;
1424  if (x > o_threshold)
1425  return huge * huge; // overflow
1426  if (x < u_threshold)
1427  return twom1000 * twom1000; // underflow
1428  }
1429 
1430  // argument reduction
1431  if (hx > 0x3fd62e42) { // if |x| > 0.5 ln2
1432  if (hx < 0x3FF0A2B2) { // and |x| < 1.5 ln2
1433  hi = x - ln2HI[xsb];
1434  lo = ln2LO[xsb];
1435  k = 1 - xsb - xsb;
1436  } else {
1437  k = (int) (invln2 * x + halF[xsb]);
1438  t = k;
1439  hi = x - t * ln2HI[0]; // t*ln2HI is exact here
1440  lo = t * ln2LO[0];
1441  }
1442  x = hi - lo;
1443  } else if (hx < 0x3e300000) { // when |x|<2**-28
1444  if (huge + x > one)
1445  return one + x;// trigger inexact
1446  } else
1447  k = 0;
1448 
1449  // x is now in primary range
1450  t = x * x;
1451  c = x - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5))));
1452  if (k == 0)
1453  return one - ((x * c) / (c - 2.0) - x);
1454  else
1455  y = one - ((lo - (x * c) / (2.0 - c)) - hi);
1456  long yBits = Double.doubleToLongBits(y);
1457  int __HIy = (int) (yBits >> 32);
1458  if (k >= -1021) {
1459  __HIy += (k << 20); // add k to y's exponent
1460  yBits = ((__HIy & 0xFFFFFFFFL) << 32) | (yBits & 0xFFFFFFFFL);
1461  y = Double.longBitsToDouble(yBits);
1462  return y;
1463  } else {
1464  __HIy += ((k + 1000) << 20);// add k to y's exponent
1465  yBits = ((__HIy & 0xFFFFFFFFL) << 32) | (yBits & 0xFFFFFFFFL);
1466  y = Double.longBitsToDouble(yBits);
1467  return y * twom1000;
1468  }
1469  }

References javolution.lang.MathLib.halF, javolution.lang.MathLib.huge, javolution.lang.MathLib.invln2, javolution.lang.MathLib.ln2HI, javolution.lang.MathLib.ln2LO, javolution.lang.MathLib.o_threshold, javolution.lang.MathLib.one, javolution.lang.MathLib.P1, javolution.lang.MathLib.P2, javolution.lang.MathLib.P3, javolution.lang.MathLib.P4, javolution.lang.MathLib.P5, javolution.lang.MathLib.twom1000, and javolution.lang.MathLib.u_threshold.

Referenced by javolution.lang.MathLib.exp().

Here is the caller graph for this function:

◆ _ieee754_log()

static double javolution.lang.MathLib._ieee754_log ( double  x)
staticpackage

Definition at line 1244 of file MathLib.java.

1244  {
1245  double hfsq, f, s, z, R, w, t1, t2, dk;
1246  int k, hx, i, j;
1247  int lx; // unsigned
1248 
1249  long xBits = Double.doubleToLongBits(x);
1250  hx = (int) (xBits >> 32);
1251  lx = (int) xBits;
1252 
1253  k = 0;
1254  if (hx < 0x00100000) { // x < 2**-1022
1255  if (((hx & 0x7fffffff) | lx) == 0)
1256  return -two54 / zero; // log(+-0)=-inf
1257  if (hx < 0)
1258  return (x - x) / zero; // log(-#) = NaN
1259  k -= 54;
1260  x *= two54; // subnormal number, scale up x
1261  xBits = Double.doubleToLongBits(x);
1262  hx = (int) (xBits >> 32); // high word of x
1263  }
1264  if (hx >= 0x7ff00000)
1265  return x + x;
1266  k += (hx >> 20) - 1023;
1267  hx &= 0x000fffff;
1268  i = (hx + 0x95f64) & 0x100000;
1269  xBits = Double.doubleToLongBits(x);
1270  int HIx = hx | (i ^ 0x3ff00000); // normalize x or x/2
1271  xBits = ((HIx & 0xFFFFFFFFL) << 32) | (xBits & 0xFFFFFFFFL);
1272  x = Double.longBitsToDouble(xBits);
1273  k += (i >> 20);
1274  f = x - 1.0;
1275  if ((0x000fffff & (2 + hx)) < 3) { // |f| < 2**-20
1276  if (f == zero)
1277  if (k == 0)
1278  return zero;
1279  else {
1280  dk = (double) k;
1281  return dk * ln2_hi + dk * ln2_lo;
1282  }
1283  R = f * f * (0.5 - 0.33333333333333333 * f);
1284  if (k == 0)
1285  return f - R;
1286  else {
1287  dk = (double) k;
1288  return dk * ln2_hi - ((R - dk * ln2_lo) - f);
1289  }
1290  }
1291  s = f / (2.0 + f);
1292  dk = (double) k;
1293  z = s * s;
1294  i = hx - 0x6147a;
1295  w = z * z;
1296  j = 0x6b851 - hx;
1297  t1 = w * (Lg2 + w * (Lg4 + w * Lg6));
1298  t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));
1299  i |= j;
1300  R = t2 + t1;
1301  if (i > 0) {
1302  hfsq = 0.5 * f * f;
1303  if (k == 0)
1304  return f - (hfsq - s * (hfsq + R));
1305  else
1306  return dk * ln2_hi
1307  - ((hfsq - (s * (hfsq + R) + dk * ln2_lo)) - f);
1308  } else if (k == 0)
1309  return f - s * (f - R);
1310  else
1311  return dk * ln2_hi - ((s * (f - R) - dk * ln2_lo) - f);
1312  }

References javolution.lang.MathLib.Lg1, javolution.lang.MathLib.Lg2, javolution.lang.MathLib.Lg3, javolution.lang.MathLib.Lg4, javolution.lang.MathLib.Lg5, javolution.lang.MathLib.Lg6, javolution.lang.MathLib.Lg7, javolution.lang.MathLib.ln2_hi, javolution.lang.MathLib.ln2_lo, javolution.lang.MathLib.two54, and javolution.lang.MathLib.zero.

Referenced by javolution.lang.MathLib.log().

Here is the caller graph for this function:

◆ abs() [1/4]

static double javolution.lang.MathLib.abs ( double  d)
static

Returns the absolute value of the specified double argument.

Parameters
dthe double value.
Returns
d or -d

Definition at line 951 of file MathLib.java.

951  {
952  return (d < 0) ? -d : d;
953  }

◆ abs() [2/4]

static float javolution.lang.MathLib.abs ( float  f)
static

Returns the absolute value of the specified float argument.

Parameters
fthe float value.
Returns
f or -f

Definition at line 941 of file MathLib.java.

941  {
942  return (f < 0) ? -f : f;
943  }

◆ abs() [3/4]

static int javolution.lang.MathLib.abs ( int  i)
static

Returns the absolute value of the specified int argument.

Parameters
ithe int value.
Returns
i or -i

Definition at line 921 of file MathLib.java.

921  {
922  return (i < 0) ? -i : i;
923  }

Referenced by javolution.lang.MathLib._atan(), javolution.text.TextBuilder.append(), javolution.text.TypeFormat.format(), and javolution.lang.MathLib.rem().

Here is the caller graph for this function:

◆ abs() [4/4]

static long javolution.lang.MathLib.abs ( long  l)
static

Returns the absolute value of the specified long argument.

Parameters
lthe long value.
Returns
l or -l

Definition at line 931 of file MathLib.java.

931  {
932  return (l < 0) ? -l : l;
933  }

◆ acos()

static double javolution.lang.MathLib.acos ( double  x)
static

Returns the arc cosine of the specified value, in the range of 0.0 through pi.

Parameters
xthe value whose arc cosine is to be returned.
Returns
the arc cosine in radians for the specified value.

Definition at line 760 of file MathLib.java.

760  {
761  return HALF_PI - MathLib.asin(x);
762  }

References javolution.lang.MathLib.asin(), and javolution.lang.MathLib.HALF_PI.

Here is the call graph for this function:

◆ asin()

static double javolution.lang.MathLib.asin ( double  x)
static

Returns the arc sine of the specified value, in the range of -pi/2 through pi/2.

Parameters
xthe value whose arc sine is to be returned.
Returns
the arc sine in radians for the specified value.

Definition at line 741 of file MathLib.java.

741  {
742  if (x < -1.0 || x > 1.0)
743  return MathLib.NaN;
744  if (x == -1.0)
745  return -HALF_PI;
746  if (x == 1.0)
747  return HALF_PI;
748  return MathLib.atan(x / MathLib.sqrt(1.0 - x * x));
749  }

References javolution.lang.MathLib.atan(), javolution.lang.MathLib.HALF_PI, javolution.lang.MathLib.NaN, and javolution.lang.MathLib.sqrt().

Referenced by javolution.lang.MathLib.acos().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ atan()

static double javolution.lang.MathLib.atan ( double  x)
static

Returns the arc tangent of the specified value, in the range of -pi/2 through pi/2.

Parameters
xthe value whose arc tangent is to be returned.
Returns
the arc tangent in radians for the specified value.
See also
Inverse Tangent – from MathWorld

Definition at line 775 of file MathLib.java.

775  {
776  return MathLib._atan(x);
777  }

References javolution.lang.MathLib._atan().

Referenced by javolution.lang.MathLib.asin(), and javolution.lang.MathLib.atan2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ atan2()

static double javolution.lang.MathLib.atan2 ( double  y,
double  x 
)
static

Returns the angle theta such that (x == cos(theta)) && (y == sin(theta)).

Parameters
ythe y value.
xthe x value.
Returns
the angle theta in radians.
See also
Wikipedia: Atan2

Definition at line 790 of file MathLib.java.

790  {
791  // From Wikipedia.
792  if (x > 0) return MathLib.atan(y / x);
793  if ((y >= 0) && (x < 0)) return MathLib.atan(y / x) + PI;
794  if ((y < 0) && (x < 0)) return MathLib.atan(y / x) - PI;
795  if ((y > 0) && (x == 0)) return PI / 2;
796  if ((y < 0) && (x == 0)) return -PI / 2;
797  return Double.NaN; // ((y == 0) && (x == 0))
798  }

References javolution.lang.MathLib.atan(), and javolution.lang.MathLib.PI.

Here is the call graph for this function:

◆ bitCount()

static int javolution.lang.MathLib.bitCount ( long  longValue)
static

Returns the number of one-bits in the two's complement binary representation of the specified long value. This function is sometimes referred to as the population count.

Parameters
longValuethe long value.
Returns
the number of one-bits in the two's complement binary representation of the specified longValue.

Definition at line 97 of file MathLib.java.

97  {
98  longValue = longValue - ((longValue >>> 1) & 0x5555555555555555L);
99  longValue = (longValue & 0x3333333333333333L)
100  + ((longValue >>> 2) & 0x3333333333333333L);
101  longValue = (longValue + (longValue >>> 4)) & 0x0f0f0f0f0f0f0f0fL;
102  longValue = longValue + (longValue >>> 8);
103  longValue = longValue + (longValue >>> 16);
104  longValue = longValue + (longValue >>> 32);
105  return (int) longValue & 0x7f;
106  }

Referenced by javolution.util.internal.bitset.BitSetServiceImpl.cardinality().

Here is the caller graph for this function:

◆ bitLength() [1/2]

static int javolution.lang.MathLib.bitLength ( int  i)
static

Returns the number of bits in the minimal two's-complement representation of the specified int, excluding a sign bit. For positive int, this is equivalent to the number of bits in the ordinary binary representation. For negative int, it is equivalent to the number of bits of the positive value -(i + 1).

Parameters
ithe int value for which the bit length is returned.
Returns
the bit length of i.

Definition at line 38 of file MathLib.java.

38  {
39  if (i < 0)
40  i = -++i;
41  return (i < 1 << 16) ? (i < 1 << 8) ? BIT_LENGTH[i]
42  : BIT_LENGTH[i >>> 8] + 8
43  : (i < 1 << 24) ? BIT_LENGTH[i >>> 16] + 16
44  : BIT_LENGTH[i >>> 24] + 24;
45  }

References javolution.lang.MathLib.BIT_LENGTH.

Referenced by javolution.lang.MathLib.bitLength(), javolution.lang.MathLib.toDoublePow10(), javolution.lang.MathLib.toDoublePow2(), and javolution.lang.MathLib.toLongPow10().

Here is the caller graph for this function:

◆ bitLength() [2/2]

static int javolution.lang.MathLib.bitLength ( long  l)
static

Returns the number of bits in the minimal two's-complement representation of the specified long, excluding a sign bit. For positive long, this is equivalent to the number of bits in the ordinary binary representation. For negative long, it is equivalent to the number of bits of the positive value -(l + 1).

Parameters
lthe long value for which the bit length is returned.
Returns
the bit length of l.

Definition at line 72 of file MathLib.java.

72  {
73  int i = (int) (l >> 32);
74  if (i > 0)
75  return (i < 1 << 16) ? (i < 1 << 8) ? BIT_LENGTH[i] + 32
76  : BIT_LENGTH[i >>> 8] + 40
77  : (i < 1 << 24) ? BIT_LENGTH[i >>> 16] + 48
78  : BIT_LENGTH[i >>> 24] + 56;
79  if (i < 0)
80  return bitLength(-++l);
81  i = (int) l;
82  return (i < 0) ? 32 : (i < 1 << 16) ? (i < 1 << 8) ? BIT_LENGTH[i]
83  : BIT_LENGTH[i >>> 8] + 8
84  : (i < 1 << 24) ? BIT_LENGTH[i >>> 16] + 16
85  : BIT_LENGTH[i >>> 24] + 24;
86  }

References javolution.lang.MathLib.BIT_LENGTH, and javolution.lang.MathLib.bitLength().

Here is the call graph for this function:

◆ ceil()

static double javolution.lang.MathLib.ceil ( double  x)
static

Returns the smallest (closest to negative infinity) double value that is not less than the argument and is equal to a mathematical integer.

Parameters
xthe value.
Returns
java.lang.Math.ceil(x)

Definition at line 678 of file MathLib.java.

678  {
679  return Math.ceil(x); // CLDC 1.1
680  }

◆ cos()

static double javolution.lang.MathLib.cos ( double  radians)
static

Returns the trigonometric cosine of the specified angle in radians.

Parameters
radiansthe angle in radians.
Returns
java.lang.Math.cos(radians)

Definition at line 716 of file MathLib.java.

716  {
717  return Math.cos(radians); // CLDC 1.1
718  }

◆ cosh()

static double javolution.lang.MathLib.cosh ( double  x)
static

Returns the hyperbolic cosine of x.

Parameters
xthe value for which the hyperbolic cosine is calculated.
Returns
(exp(x) + exp(-x)) / 2

Definition at line 820 of file MathLib.java.

820  {
821  return (MathLib.exp(x) + MathLib.exp(-x)) * 0.5;
822  }

References javolution.lang.MathLib.exp().

Here is the call graph for this function:

◆ digitLength() [1/2]

static int javolution.lang.MathLib.digitLength ( int  i)
static

Returns the number of digits of the decimal representation of the specified int value, excluding the sign character if any.

Parameters
ithe int value for which the digit length is returned.
Returns
String.valueOf(i).length() for zero or positive values; String.valueOf(i).length() - 1 for negative values.

Definition at line 161 of file MathLib.java.

161  {
162  if (i >= 0)
163  return (i >= 100000) ? (i >= 10000000) ? (i >= 1000000000) ? 10
164  : (i >= 100000000) ? 9 : 8 : (i >= 1000000) ? 7 : 6
165  : (i >= 100) ? (i >= 10000) ? 5 : (i >= 1000) ? 4 : 3
166  : (i >= 10) ? 2 : 1;
167  if (i == Integer.MIN_VALUE)
168  return 10; // "2147483648".length()
169  return digitLength(-i); // No overflow possible.
170  }

Referenced by javolution.text.TextBuilder.append(), javolution.text.TextBuilder.appendFraction(), and javolution.lang.MathLib.digitLength().

Here is the caller graph for this function:

◆ digitLength() [2/2]

static int javolution.lang.MathLib.digitLength ( long  l)
static

Returns the number of digits of the decimal representation of the the specified long, excluding the sign character if any.

Parameters
lthe long value for which the digit length is returned.
Returns
String.valueOf(l).length() for zero or positive values; String.valueOf(l).length() - 1 for negative values.

Definition at line 180 of file MathLib.java.

180  {
181  if (l >= 0)
182  return (l <= Integer.MAX_VALUE) ? digitLength((int) l)
183  : // At least 10 digits or more.
184  (l >= 100000000000000L) ? (l >= 10000000000000000L) ? (l >= 1000000000000000000L) ? 19
185  : (l >= 100000000000000000L) ? 18 : 17
186  : (l >= 1000000000000000L) ? 16 : 15
187  : (l >= 100000000000L) ? (l >= 10000000000000L) ? 14
188  : (l >= 1000000000000L) ? 13 : 12
189  : (l >= 10000000000L) ? 11 : 10;
190  if (l == Long.MIN_VALUE)
191  return 19; // "9223372036854775808".length()
192  return digitLength(-l);
193  }

References javolution.lang.MathLib.digitLength().

Here is the call graph for this function:

◆ exp()

static double javolution.lang.MathLib.exp ( double  x)
static

Returns e raised to the specified power.

Parameters
xthe exponent.
Returns
ex
See also
Exponential Function – from MathWorld

Definition at line 846 of file MathLib.java.

846  {
847  return MathLib._ieee754_exp(x);
848  }

References javolution.lang.MathLib._ieee754_exp().

Referenced by javolution.lang.MathLib.cosh(), javolution.lang.MathLib.floorLog2(), javolution.lang.MathLib.pow(), javolution.lang.MathLib.sinh(), javolution.lang.MathLib.tanh(), javolution.lang.MathLib.toDoublePow2(), javolution.lang.MathLib.toLongPow10(), and javolution.lang.MathLib.toLongPow2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ floor()

static double javolution.lang.MathLib.floor ( double  x)
static

Returns the largest (closest to positive infinity) double value that is not greater than the argument and is equal to a mathematical integer.

Parameters
xthe value.
Returns
java.lang.Math.ceil(x)

Definition at line 692 of file MathLib.java.

692  {
693  return Math.floor(x); // CLDC 1.1
694  }

Referenced by javolution.lang.MathLib.round().

Here is the caller graph for this function:

◆ floorLog10()

static int javolution.lang.MathLib.floorLog10 ( double  d)
static

Returns the largest power of 10 that is less than or equal to the the specified positive value.

Parameters
dthe double number.
Returns
floor(Log10(abs(d)))
Exceptions
ArithmeticExceptionif d <= 0 or d is NaN or Infinity.

Definition at line 549 of file MathLib.java.

549  {
550  int guess = (int) (LOG2_DIV_LOG10 * MathLib.floorLog2(d));
551  double pow10 = MathLib.toDoublePow10(1, guess);
552  if ((pow10 <= d) && (pow10 * 10 > d))
553  return guess;
554  if (pow10 > d)
555  return guess - 1;
556  return guess + 1;
557  }

References javolution.lang.MathLib.floorLog2(), javolution.lang.MathLib.LOG2_DIV_LOG10, and javolution.lang.MathLib.toDoublePow10().

Referenced by javolution.text.TextBuilder.append().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ floorLog2()

static int javolution.lang.MathLib.floorLog2 ( double  d)
static

Returns the largest power of 2 that is less than or equal to the the specified positive value.

Parameters
dthe double number.
Returns
floor(Log2(abs(d)))
Exceptions
ArithmeticExceptionif d <= 0 or d is NaN or Infinity.

Definition at line 526 of file MathLib.java.

526  {
527  if (d <= 0)
528  throw new ArithmeticException("Negative number or zero");
529  long bits = Double.doubleToLongBits(d);
530  int exp = ((int) (bits >> 52)) & 0x7FF;
531  if (exp == 0x7FF)
532  throw new ArithmeticException("Infinity or NaN");
533  if (exp == 0)
534  return floorLog2(d * 18014398509481984L) - 54; // 2^54 Exact.
535  return exp - 1023;
536  }

References javolution.lang.MathLib.exp().

Referenced by javolution.lang.MathLib.floorLog10().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ log()

static double javolution.lang.MathLib.log ( double  x)
static

Returns the natural logarithm (base e) of the specified value.

Parameters
xthe value greater than 0.0.
Returns
the value y such as ey == x

Definition at line 859 of file MathLib.java.

859  {
860  return MathLib._ieee754_log(x);
861  }

References javolution.lang.MathLib._ieee754_log().

Referenced by javolution.lang.MathLib.log10(), and javolution.lang.MathLib.pow().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ log10()

static double javolution.lang.MathLib.log10 ( double  x)
static

Returns the decimal logarithm of the specified value.

Parameters
xthe value greater than 0.0.
Returns
the value y such as 10y == x

Definition at line 871 of file MathLib.java.

871  {
872  return log(x) * INV_LOG10;
873  }

References javolution.lang.MathLib.INV_LOG10, and javolution.lang.MathLib.log().

Here is the call graph for this function:

◆ max() [1/4]

static double javolution.lang.MathLib.max ( double  x,
double  y 
)
static

Returns the greater of two double values.

Parameters
xthe first value.
ythe second value.
Returns
the larger of x and y.

Definition at line 997 of file MathLib.java.

997  {
998  return (x >= y) ? x : y;
999  }

◆ max() [2/4]

static float javolution.lang.MathLib.max ( float  x,
float  y 
)
static

Returns the greater of two float values.

Parameters
xthe first value.
ythe second value.
Returns
the larger of x and y.

Definition at line 986 of file MathLib.java.

986  {
987  return (x >= y) ? x : y;
988  }

◆ max() [3/4]

static int javolution.lang.MathLib.max ( int  x,
int  y 
)
static

Returns the greater of two int values.

Parameters
xthe first value.
ythe second value.
Returns
the larger of x and y.

Definition at line 964 of file MathLib.java.

964  {
965  return (x >= y) ? x : y;
966  }

Referenced by javolution.text.Text.getDepth(), javolution.text.Text.indexOf(), and javolution.io.Struct.Member.Member().

Here is the caller graph for this function:

◆ max() [4/4]

static long javolution.lang.MathLib.max ( long  x,
long  y 
)
static

Returns the greater of two long values.

Parameters
xthe first value.
ythe second value.
Returns
the larger of x and y.

Definition at line 975 of file MathLib.java.

975  {
976  return (x >= y) ? x : y;
977  }

◆ min() [1/4]

static double javolution.lang.MathLib.min ( double  x,
double  y 
)
static

Returns the smaller of two double values.

Parameters
xthe first value.
ythe second value.
Returns
the smaller of x and y.

Definition at line 1045 of file MathLib.java.

1045  {
1046  return (x < y) ? x : y;
1047  }

◆ min() [2/4]

static float javolution.lang.MathLib.min ( float  x,
float  y 
)
static

Returns the smaller of two float values.

Parameters
xthe first value.
ythe second value.
Returns
the smaller of x and y.

Definition at line 1032 of file MathLib.java.

1032  {
1033  return (x < y) ? x : y;
1034  }

◆ min() [3/4]

static int javolution.lang.MathLib.min ( int  x,
int  y 
)
static

◆ min() [4/4]

static long javolution.lang.MathLib.min ( long  x,
long  y 
)
static

Returns the smaller of two long values.

Parameters
xthe first value.
ythe second value.
Returns
the smaller of x and y.

Definition at line 1021 of file MathLib.java.

1021  {
1022  return (x < y) ? x : y;
1023  }

◆ numberOfLeadingZeros()

static int javolution.lang.MathLib.numberOfLeadingZeros ( long  longValue)
static

Returns the number of zero bits preceding the highest-order ("leftmost") one-bit in the two's complement binary representation of the specified long value. Returns 64 if the specifed value is zero.

Parameters
longValuethe long value.
Returns
the number of leading zero bits.

Definition at line 117 of file MathLib.java.

117  {
118  // From Hacker's Delight
119  if (longValue == 0)
120  return 64;
121  int n = 1;
122  int x = (int)(longValue >>> 32);
123  if (x == 0) { n += 32; x = (int)longValue; }
124  if (x >>> 16 == 0) { n += 16; x <<= 16; }
125  if (x >>> 24 == 0) { n += 8; x <<= 8; }
126  if (x >>> 28 == 0) { n += 4; x <<= 4; }
127  if (x >>> 30 == 0) { n += 2; x <<= 2; }
128  n -= x >>> 31;
129  return n;
130  }

Referenced by javolution.util.internal.bitset.BitSetServiceImpl.length().

Here is the caller graph for this function:

◆ numberOfTrailingZeros()

static int javolution.lang.MathLib.numberOfTrailingZeros ( long  longValue)
static

Returns the number of zero bits following the lowest-order ("rightmost") one-bit in the two's complement binary representation of the specified long value. Returns 64 if the specifed value is zero.

Parameters
longValuethe long value.
Returns
the number of trailing zero bits.

Definition at line 140 of file MathLib.java.

140  {
141  // From Hacker's Delight
142  int x, y;
143  if (longValue == 0) return 64;
144  int n = 63;
145  y = (int)longValue; if (y != 0) { n = n -32; x = y; } else x = (int)(longValue>>>32);
146  y = x <<16; if (y != 0) { n = n -16; x = y; }
147  y = x << 8; if (y != 0) { n = n - 8; x = y; }
148  y = x << 4; if (y != 0) { n = n - 4; x = y; }
149  y = x << 2; if (y != 0) { n = n - 2; x = y; }
150  return n - ((x << 1) >>> 31);
151  }

◆ pow()

static double javolution.lang.MathLib.pow ( double  x,
double  y 
)
static

Returns the value of the first argument raised to the power of the second argument.

Parameters
xthe base.
ythe exponent.
Returns
xy

Definition at line 885 of file MathLib.java.

885  {
886  // Use close approximation (+/- LSB)
887  if ((x < 0) && (y == (int) y))
888  return (((int) y) & 1) == 0 ? pow(-x, y) : -pow(-x, y);
889  return MathLib.exp(y * MathLib.log(x));
890  }

References javolution.lang.MathLib.exp(), and javolution.lang.MathLib.log().

Here is the call graph for this function:

◆ rem()

static double javolution.lang.MathLib.rem ( double  x,
double  y 
)
static

Returns the remainder of the division of the specified two arguments.

Parameters
xthe dividend.
ythe divisor.
Returns
x - round(x / y) * y

Definition at line 660 of file MathLib.java.

660  {
661  double tmp = x / y;
662  if (MathLib.abs(tmp) <= Long.MAX_VALUE)
663  return x - MathLib.round(tmp) * y;
664  else
665  return NaN;
666  }

References javolution.lang.MathLib.abs(), javolution.lang.MathLib.NaN, and javolution.lang.MathLib.round().

Here is the call graph for this function:

◆ round() [1/2]

static long javolution.lang.MathLib.round ( double  d)
static

Returns the closest long to the specified argument.

Parameters
dthe double value to be rounded to a long
Returns
the nearest long value.

Definition at line 911 of file MathLib.java.

911  {
912  return (long) floor(d + 0.5d);
913  }

References javolution.lang.MathLib.floor().

Here is the call graph for this function:

◆ round() [2/2]

static int javolution.lang.MathLib.round ( float  f)
static

Returns the closest int to the specified argument.

Parameters
fthe float value to be rounded to a int
Returns
the nearest int value.

Definition at line 898 of file MathLib.java.

898  {
899  return (int) floor(f + 0.5f);
900  }

References javolution.lang.MathLib.floor().

Referenced by javolution.lang.MathLib.rem().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sin()

static double javolution.lang.MathLib.sin ( double  radians)
static

Returns the trigonometric sine of the specified angle in radians.

Parameters
radiansthe angle in radians.
Returns
java.lang.Math.sin(radians)

Definition at line 704 of file MathLib.java.

704  {
705  return Math.sin(radians); // CLDC 1.1
706  }

◆ sinh()

static double javolution.lang.MathLib.sinh ( double  x)
static

Returns the hyperbolic sine of x.

Parameters
xthe value for which the hyperbolic sine is calculated.
Returns
(exp(x) - exp(-x)) / 2

Definition at line 808 of file MathLib.java.

808  {
809  return (MathLib.exp(x) - MathLib.exp(-x)) * 0.5;
810  }

References javolution.lang.MathLib.exp().

Here is the call graph for this function:

◆ sqrt()

static double javolution.lang.MathLib.sqrt ( double  x)
static

Returns the positive square root of the specified value.

Parameters
xthe value.
Returns
java.lang.Math.sqrt(x)

Definition at line 647 of file MathLib.java.

647  {
648  return Math.sqrt(x); // CLDC 1.1
649  }

Referenced by javolution.lang.MathLib.asin().

Here is the caller graph for this function:

◆ tan()

static double javolution.lang.MathLib.tan ( double  radians)
static

Returns the trigonometric tangent of the specified angle in radians.

Parameters
radiansthe angle in radians.
Returns
java.lang.Math.tan(radians)

Definition at line 728 of file MathLib.java.

728  {
729  return Math.tan(radians); // CLDC 1.1
730  }

◆ tanh()

static double javolution.lang.MathLib.tanh ( double  x)
static

Returns the hyperbolic tangent of x.

Parameters
xthe value for which the hyperbolic tangent is calculated.
Returns
(exp(2 * x) - 1) / (exp(2 * x) + 1)

Definition at line 832 of file MathLib.java.

832  {
833  return (MathLib.exp(2 * x) - 1) / (MathLib.exp(2 * x) + 1);
834  }

References javolution.lang.MathLib.exp().

Here is the call graph for this function:

◆ toDegrees()

static double javolution.lang.MathLib.toDegrees ( double  radians)
static

Converts an angle in radians to degrees.

Parameters
radiansthe angle in radians.
Returns
the specified angle in degrees.

Definition at line 635 of file MathLib.java.

635  {
636  return radians * (180.0 / PI);
637  }

References javolution.lang.MathLib.PI.

◆ toDoublePow10()

static double javolution.lang.MathLib.toDoublePow10 ( long  m,
int  n 
)
static

Returns the closest double representation of the specified long number multiplied by a power of ten.

Parameters
mthe long multiplier.
nthe power of ten exponent.
Returns
multiplier * 10n.

Definition at line 240 of file MathLib.java.

240  {
241  if (m == 0)
242  return 0.0;
243  if (m == Long.MIN_VALUE)
244  return toDoublePow10(Long.MIN_VALUE / 10, n + 1);
245  if (m < 0)
246  return -toDoublePow10(-m, n);
247  if (n >= 0) { // Positive power.
248  if (n > 308)
249  return Double.POSITIVE_INFINITY;
250  // Works with 4 x 32 bits registers (x3:x2:x1:x0)
251  long x0 = 0; // 32 bits.
252  long x1 = 0; // 32 bits.
253  long x2 = m & MASK_32; // 32 bits.
254  long x3 = m >>> 32; // 32 bits.
255  int pow2 = 0;
256  while (n != 0) {
257  int i = (n >= POW5_INT.length) ? POW5_INT.length - 1 : n;
258  int coef = POW5_INT[i]; // 31 bits max.
259 
260  if (((int) x0) != 0)
261  x0 *= coef; // 63 bits max.
262  if (((int) x1) != 0)
263  x1 *= coef; // 63 bits max.
264  x2 *= coef; // 63 bits max.
265  x3 *= coef; // 63 bits max.
266 
267  x1 += x0 >>> 32;
268  x0 &= MASK_32;
269 
270  x2 += x1 >>> 32;
271  x1 &= MASK_32;
272 
273  x3 += x2 >>> 32;
274  x2 &= MASK_32;
275 
276  // Adjusts powers.
277  pow2 += i;
278  n -= i;
279 
280  // Normalizes (x3 should be 32 bits max).
281  long carry = x3 >>> 32;
282  if (carry != 0) { // Shift.
283  x0 = x1;
284  x1 = x2;
285  x2 = x3 & MASK_32;
286  x3 = carry;
287  pow2 += 32;
288  }
289  }
290 
291  // Merges registers to a 63 bits mantissa.
292  int shift = 31 - MathLib.bitLength(x3); // -1..30
293  pow2 -= shift;
294  long mantissa = (shift < 0) ? (x3 << 31) | (x2 >>> 1) : // x3 is 32 bits.
295  (((x3 << 32) | x2) << shift) | (x1 >>> (32 - shift));
296  return toDoublePow2(mantissa, pow2);
297 
298  } else { // n < 0
299  if (n < -324 - 20)
300  return 0.0;
301 
302  // Works with x1:x0 126 bits register.
303  long x1 = m; // 63 bits.
304  long x0 = 0; // 63 bits.
305  int pow2 = 0;
306  while (true) {
307 
308  // Normalizes x1:x0
309  int shift = 63 - MathLib.bitLength(x1);
310  x1 <<= shift;
311  x1 |= x0 >>> (63 - shift);
312  x0 = (x0 << shift) & MASK_63;
313  pow2 -= shift;
314 
315  // Checks if division has to be performed.
316  if (n == 0)
317  break; // Done.
318 
319  // Retrieves power of 5 divisor.
320  int i = (-n >= POW5_INT.length) ? POW5_INT.length - 1 : -n;
321  int divisor = POW5_INT[i];
322 
323  // Performs the division (126 bits by 31 bits).
324  long wh = (x1 >>> 32);
325  long qh = wh / divisor;
326  long r = wh - qh * divisor;
327  long wl = (r << 32) | (x1 & MASK_32);
328  long ql = wl / divisor;
329  r = wl - ql * divisor;
330  x1 = (qh << 32) | ql;
331 
332  wh = (r << 31) | (x0 >>> 32);
333  qh = wh / divisor;
334  r = wh - qh * divisor;
335  wl = (r << 32) | (x0 & MASK_32);
336  ql = wl / divisor;
337  x0 = (qh << 32) | ql;
338 
339  // Adjusts powers.
340  n += i;
341  pow2 -= i;
342  }
343  return toDoublePow2(x1, pow2);
344  }
345  }

References javolution.lang.MathLib.bitLength(), javolution.lang.MathLib.MASK_32, javolution.lang.MathLib.MASK_63, javolution.lang.MathLib.POW5_INT, and javolution.lang.MathLib.toDoublePow2().

Referenced by javolution.text.TextBuilder.append(), javolution.lang.MathLib.floorLog10(), and javolution.text.TypeFormat.parseDouble().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toDoublePow2()

static double javolution.lang.MathLib.toDoublePow2 ( long  m,
int  n 
)
static

Returns the closest double representation of the specified long number multiplied by a power of two.

Parameters
mthe long multiplier.
nthe power of two exponent.
Returns
m * 2n.

Definition at line 203 of file MathLib.java.

203  {
204  if (m == 0)
205  return 0.0;
206  if (m == Long.MIN_VALUE)
207  return toDoublePow2(Long.MIN_VALUE >> 1, n + 1);
208  if (m < 0)
209  return -toDoublePow2(-m, n);
210  int bitLength = MathLib.bitLength(m);
211  int shift = bitLength - 53;
212  long exp = 1023L + 52 + n + shift; // Use long to avoid overflow.
213  if (exp >= 0x7FF)
214  return Double.POSITIVE_INFINITY;
215  if (exp <= 0) { // Degenerated number (subnormal, assume 0 for bit 52)
216  if (exp <= -54)
217  return 0.0;
218  return toDoublePow2(m, n + 54) / 18014398509481984L; // 2^54 Exact.
219  }
220  // Normal number.
221  long bits = (shift > 0) ? (m >> shift) + ((m >> (shift - 1)) & 1) : // Rounding.
222  m << -shift;
223  if (((bits >> 52) != 1) && (++exp >= 0x7FF))
224  return Double.POSITIVE_INFINITY;
225  bits &= 0x000fffffffffffffL; // Clears MSB (bit 52)
226  bits |= exp << 52;
227  return Double.longBitsToDouble(bits);
228  }

References javolution.lang.MathLib.bitLength(), and javolution.lang.MathLib.exp().

Referenced by javolution.lang.MathLib.toDoublePow10().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toLongPow10()

static long javolution.lang.MathLib.toLongPow10 ( double  d,
int  n 
)
static

Returns the closest long representation of the specified double number multiplied by a power of ten.

Parameters
dthe double multiplier.
nthe power of two exponent.
Returns
d * 10n.

Definition at line 400 of file MathLib.java.

400  {
401  long bits = Double.doubleToLongBits(d);
402  boolean isNegative = (bits >> 63) != 0;
403  int exp = ((int) (bits >> 52)) & 0x7FF;
404  long m = bits & 0x000fffffffffffffL;
405  if (exp == 0x7FF)
406  throw new ArithmeticException(
407  "Cannot convert to long (Infinity or NaN)");
408  if (exp == 0) {
409  if (m == 0)
410  return 0L;
411  return toLongPow10(d * 1E16, n - 16);
412  }
413  m |= 0x0010000000000000L; // Sets MSB (bit 52)
414  int pow2 = exp - 1023 - 52;
415  // Retrieves 63 bits m with n == 0.
416  if (n >= 0) {
417  // Works with 4 x 32 bits registers (x3:x2:x1:x0)
418  long x0 = 0; // 32 bits.
419  long x1 = 0; // 32 bits.
420  long x2 = m & MASK_32; // 32 bits.
421  long x3 = m >>> 32; // 32 bits.
422  while (n != 0) {
423  int i = (n >= POW5_INT.length) ? POW5_INT.length - 1 : n;
424  int coef = POW5_INT[i]; // 31 bits max.
425 
426  if (((int) x0) != 0)
427  x0 *= coef; // 63 bits max.
428  if (((int) x1) != 0)
429  x1 *= coef; // 63 bits max.
430  x2 *= coef; // 63 bits max.
431  x3 *= coef; // 63 bits max.
432 
433  x1 += x0 >>> 32;
434  x0 &= MASK_32;
435 
436  x2 += x1 >>> 32;
437  x1 &= MASK_32;
438 
439  x3 += x2 >>> 32;
440  x2 &= MASK_32;
441 
442  // Adjusts powers.
443  pow2 += i;
444  n -= i;
445 
446  // Normalizes (x3 should be 32 bits max).
447  long carry = x3 >>> 32;
448  if (carry != 0) { // Shift.
449  x0 = x1;
450  x1 = x2;
451  x2 = x3 & MASK_32;
452  x3 = carry;
453  pow2 += 32;
454  }
455  }
456 
457  // Merges registers to a 63 bits mantissa.
458  int shift = 31 - MathLib.bitLength(x3); // -1..30
459  pow2 -= shift;
460  m = (shift < 0) ? (x3 << 31) | (x2 >>> 1) : // x3 is 32 bits.
461  (((x3 << 32) | x2) << shift) | (x1 >>> (32 - shift));
462 
463  } else { // n < 0
464 
465  // Works with x1:x0 126 bits register.
466  long x1 = m; // 63 bits.
467  long x0 = 0; // 63 bits.
468  while (true) {
469 
470  // Normalizes x1:x0
471  int shift = 63 - MathLib.bitLength(x1);
472  x1 <<= shift;
473  x1 |= x0 >>> (63 - shift);
474  x0 = (x0 << shift) & MASK_63;
475  pow2 -= shift;
476 
477  // Checks if division has to be performed.
478  if (n == 0)
479  break; // Done.
480 
481  // Retrieves power of 5 divisor.
482  int i = (-n >= POW5_INT.length) ? POW5_INT.length - 1 : -n;
483  int divisor = POW5_INT[i];
484 
485  // Performs the division (126 bits by 31 bits).
486  long wh = (x1 >>> 32);
487  long qh = wh / divisor;
488  long r = wh - qh * divisor;
489  long wl = (r << 32) | (x1 & MASK_32);
490  long ql = wl / divisor;
491  r = wl - ql * divisor;
492  x1 = (qh << 32) | ql;
493 
494  wh = (r << 31) | (x0 >>> 32);
495  qh = wh / divisor;
496  r = wh - qh * divisor;
497  wl = (r << 32) | (x0 & MASK_32);
498  ql = wl / divisor;
499  x0 = (qh << 32) | ql;
500 
501  // Adjusts powers.
502  n += i;
503  pow2 -= i;
504  }
505  m = x1;
506  }
507  if (pow2 > 0)
508  throw new ArithmeticException("Overflow");
509  if (pow2 < -63)
510  return 0;
511  m = (m >> -pow2) + ((m >> -(pow2 + 1)) & 1); // Rounding.
512  return isNegative ? -m : m;
513  }

References javolution.lang.MathLib.bitLength(), javolution.lang.MathLib.exp(), javolution.lang.MathLib.MASK_32, javolution.lang.MathLib.MASK_63, and javolution.lang.MathLib.POW5_INT.

Referenced by javolution.text.TextBuilder.append().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toLongPow2()

static long javolution.lang.MathLib.toLongPow2 ( double  d,
int  n 
)
static

Returns the closest long representation of the specified double number multiplied by a power of two.

Parameters
dthe double multiplier.
nthe power of two exponent.
Returns
d * 2n
Exceptions
ArithmeticExceptionif the conversion cannot be performed (NaN, Infinity or overflow).

Definition at line 366 of file MathLib.java.

366  {
367  long bits = Double.doubleToLongBits(d);
368  boolean isNegative = (bits >> 63) != 0;
369  int exp = ((int) (bits >> 52)) & 0x7FF;
370  long m = bits & 0x000fffffffffffffL;
371  if (exp == 0x7FF)
372  throw new ArithmeticException(
373  "Cannot convert to long (Infinity or NaN)");
374  if (exp == 0) {
375  if (m == 0)
376  return 0L;
377  return toLongPow2(d * 18014398509481984L, n - 54); // 2^54 Exact.
378  }
379  m |= 0x0010000000000000L; // Sets MSB (bit 52)
380  long shift = exp - 1023L - 52 + n; // Use long to avoid overflow.
381  if (shift <= -64)
382  return 0L;
383  if (shift >= 11)
384  throw new ArithmeticException("Cannot convert to long (overflow)");
385  m = (shift >= 0) ? m << shift : (m >> -shift)
386  + ((m >> -(shift + 1)) & 1); // Rounding.
387  return isNegative ? -m : m;
388  }

References javolution.lang.MathLib.exp().

Here is the call graph for this function:

◆ toRadians()

static double javolution.lang.MathLib.toRadians ( double  degrees)
static

Converts an angle in degrees to radians.

Parameters
degreesthe angle in degrees.
Returns
the specified angle in radians.

Definition at line 623 of file MathLib.java.

623  {
624  return degrees * (PI / 180.0);
625  }

References javolution.lang.MathLib.PI.

Member Data Documentation

◆ aT

final double javolution.lang.MathLib.aT[]
staticpackage
Initial value:
= { 3.33333333333329318027e-01,
-1.99999999998764832476e-01,
1.42857142725034663711e-01,
-1.11111104054623557880e-01,
9.09088713343650656196e-02,
-7.69187620504482999495e-02,
6.66107313738753120669e-02,
-5.83357013379057348645e-02,
4.97687799461593236017e-02,
-3.65315727442169155270e-02,
1.62858201153657823623e-02,
}

Definition at line 1094 of file MathLib.java.

Referenced by javolution.lang.MathLib._atan().

◆ atanhi

final double javolution.lang.MathLib.atanhi[]
staticpackage
Initial value:
= { 4.63647609000806093515e-01,
7.85398163397448278999e-01,
9.82793723247329054082e-01,
1.57079632679489655800e+00,
}

Definition at line 1082 of file MathLib.java.

Referenced by javolution.lang.MathLib._atan().

◆ atanlo

final double javolution.lang.MathLib.atanlo[]
staticpackage
Initial value:
= { 2.26987774529616870924e-17,
3.06161699786838301793e-17,
1.39033110312309984516e-17,
6.12323399573676603587e-17,
}

Definition at line 1088 of file MathLib.java.

Referenced by javolution.lang.MathLib._atan().

◆ BIT_LENGTH

final byte [] javolution.lang.MathLib.BIT_LENGTH
staticprivate
Initial value:
= { 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4,
4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8 }

Definition at line 47 of file MathLib.java.

Referenced by javolution.lang.MathLib.bitLength().

◆ E

final double javolution.lang.MathLib.E = 2.71828182845904523536028747135266
static

The natural logarithm.

Definition at line 564 of file MathLib.java.

◆ FOUR_PI

final double javolution.lang.MathLib.FOUR_PI = 12.566370614359172953850573533118
static

Four time the ratio of the circumference of a circle to its diameter.

Definition at line 584 of file MathLib.java.

◆ halF

final double javolution.lang.MathLib.halF[] = { 0.5, -0.5, }
staticpackage

Definition at line 1389 of file MathLib.java.

Referenced by javolution.lang.MathLib._ieee754_exp().

◆ HALF_PI

final double javolution.lang.MathLib.HALF_PI = 1.5707963267948966192313216916398
static

Half the ratio of the circumference of a circle to its diameter.

Definition at line 574 of file MathLib.java.

Referenced by javolution.lang.MathLib.acos(), and javolution.lang.MathLib.asin().

◆ huge

final double javolution.lang.MathLib.huge = 1.0e300
staticpackage

◆ Infinity

final double javolution.lang.MathLib.Infinity = 1.0 / 0.0
static

Infinity.

Definition at line 614 of file MathLib.java.

◆ INV_LOG10

double javolution.lang.MathLib.INV_LOG10 = 0.43429448190325182765112891891661
staticprivate

Definition at line 875 of file MathLib.java.

Referenced by javolution.lang.MathLib.log10().

◆ invln2

final double javolution.lang.MathLib.invln2 = 1.44269504088896338700e+00
staticpackage

Definition at line 1397 of file MathLib.java.

Referenced by javolution.lang.MathLib._ieee754_exp().

◆ Lg1

final double javolution.lang.MathLib.Lg1 = 6.666666666666735130e-01
staticpackage

Definition at line 1234 of file MathLib.java.

Referenced by javolution.lang.MathLib._ieee754_log().

◆ Lg2

final double javolution.lang.MathLib.Lg2 = 3.999999999940941908e-01
staticpackage

Definition at line 1235 of file MathLib.java.

Referenced by javolution.lang.MathLib._ieee754_log().

◆ Lg3

final double javolution.lang.MathLib.Lg3 = 2.857142874366239149e-01
staticpackage

Definition at line 1236 of file MathLib.java.

Referenced by javolution.lang.MathLib._ieee754_log().

◆ Lg4

final double javolution.lang.MathLib.Lg4 = 2.222219843214978396e-01
staticpackage

Definition at line 1237 of file MathLib.java.

Referenced by javolution.lang.MathLib._ieee754_log().

◆ Lg5

final double javolution.lang.MathLib.Lg5 = 1.818357216161805012e-01
staticpackage

Definition at line 1238 of file MathLib.java.

Referenced by javolution.lang.MathLib._ieee754_log().

◆ Lg6

final double javolution.lang.MathLib.Lg6 = 1.531383769920937332e-01
staticpackage

Definition at line 1239 of file MathLib.java.

Referenced by javolution.lang.MathLib._ieee754_log().

◆ Lg7

final double javolution.lang.MathLib.Lg7 = 1.479819860511658591e-01
staticpackage

Definition at line 1240 of file MathLib.java.

Referenced by javolution.lang.MathLib._ieee754_log().

◆ ln2_hi

final double javolution.lang.MathLib.ln2_hi = 6.93147180369123816490e-01
staticpackage

Definition at line 1231 of file MathLib.java.

Referenced by javolution.lang.MathLib._ieee754_log().

◆ ln2_lo

final double javolution.lang.MathLib.ln2_lo = 1.90821492927058770002e-10
staticpackage

Definition at line 1232 of file MathLib.java.

Referenced by javolution.lang.MathLib._ieee754_log().

◆ ln2HI

final double javolution.lang.MathLib.ln2HI[]
staticpackage
Initial value:
= { 6.93147180369123816490e-01,
-6.93147180369123816490e-01, }

Definition at line 1393 of file MathLib.java.

Referenced by javolution.lang.MathLib._ieee754_exp().

◆ ln2LO

final double javolution.lang.MathLib.ln2LO[]
staticpackage
Initial value:
= { 1.90821492927058770002e-10,
-1.90821492927058770002e-10, }

Definition at line 1395 of file MathLib.java.

Referenced by javolution.lang.MathLib._ieee754_exp().

◆ LOG10

final double javolution.lang.MathLib.LOG10 = 2.3025850929940456840179914546844
static

The natural logarithm of ten.

Definition at line 599 of file MathLib.java.

◆ LOG2

final double javolution.lang.MathLib.LOG2 = 0.69314718055994530941723212145818
static

The natural logarithm of two.

Definition at line 594 of file MathLib.java.

◆ LOG2_DIV_LOG10

final double javolution.lang.MathLib.LOG2_DIV_LOG10 = 0.3010299956639811952137388947
staticprivate

Definition at line 559 of file MathLib.java.

Referenced by javolution.lang.MathLib.floorLog10().

◆ MASK_32

final long javolution.lang.MathLib.MASK_32 = 0xFFFFFFFFL
staticprivate

◆ MASK_63

final long javolution.lang.MathLib.MASK_63 = 0x7FFFFFFFFFFFFFFFL
staticprivate

◆ NaN

final double javolution.lang.MathLib.NaN = 0.0 / 0.0
static

Not-A-Number.

Definition at line 609 of file MathLib.java.

Referenced by javolution.lang.MathLib.asin(), and javolution.lang.MathLib.rem().

◆ o_threshold

final double javolution.lang.MathLib.o_threshold = 7.09782712893383973096e+02
staticpackage

Definition at line 1391 of file MathLib.java.

Referenced by javolution.lang.MathLib._ieee754_exp().

◆ one

final double javolution.lang.MathLib.one = 1.0
staticpackage

◆ P1

final double javolution.lang.MathLib.P1 = 1.66666666666666019037e-01
staticpackage

Definition at line 1398 of file MathLib.java.

Referenced by javolution.lang.MathLib._ieee754_exp().

◆ P2

final double javolution.lang.MathLib.P2 = -2.77777777770155933842e-03
staticpackage

Definition at line 1399 of file MathLib.java.

Referenced by javolution.lang.MathLib._ieee754_exp().

◆ P3

final double javolution.lang.MathLib.P3 = 6.61375632143793436117e-05
staticpackage

Definition at line 1400 of file MathLib.java.

Referenced by javolution.lang.MathLib._ieee754_exp().

◆ P4

final double javolution.lang.MathLib.P4 = -1.65339022054652515390e-06
staticpackage

Definition at line 1401 of file MathLib.java.

Referenced by javolution.lang.MathLib._ieee754_exp().

◆ P5

final double javolution.lang.MathLib.P5 = 4.13813679705723846039e-08
staticpackage

Definition at line 1402 of file MathLib.java.

Referenced by javolution.lang.MathLib._ieee754_exp().

◆ PI

final double javolution.lang.MathLib.PI = 3.1415926535897932384626433832795
static

The ratio of the circumference of a circle to its diameter.

Definition at line 569 of file MathLib.java.

Referenced by javolution.lang.MathLib.atan2(), javolution.lang.MathLib.toDegrees(), and javolution.lang.MathLib.toRadians().

◆ PI_SQUARE

final double javolution.lang.MathLib.PI_SQUARE = 9.8696044010893586188344909998762
static

Holds PI * PI.

Definition at line 589 of file MathLib.java.

◆ POW5_INT

final int [] javolution.lang.MathLib.POW5_INT
staticprivate
Initial value:
= { 1, 5, 25, 125, 625, 3125, 15625,
78125, 390625, 1953125, 9765625, 48828125, 244140625, 1220703125 }

Definition at line 351 of file MathLib.java.

Referenced by javolution.lang.MathLib.toDoublePow10(), and javolution.lang.MathLib.toLongPow10().

◆ SQRT2

final double javolution.lang.MathLib.SQRT2 = 1.4142135623730950488016887242097
static

The square root of two.

Definition at line 604 of file MathLib.java.

◆ two54

final double javolution.lang.MathLib.two54 = 1.80143985094819840000e+16
staticpackage

Definition at line 1233 of file MathLib.java.

Referenced by javolution.lang.MathLib._ieee754_log().

◆ TWO_PI

final double javolution.lang.MathLib.TWO_PI = 6.283185307179586476925286766559
static

Twice the ratio of the circumference of a circle to its diameter.

Definition at line 579 of file MathLib.java.

◆ twom1000

final double javolution.lang.MathLib.twom1000 = 9.33263618503218878990e-302
staticpackage

Definition at line 1390 of file MathLib.java.

Referenced by javolution.lang.MathLib._ieee754_exp().

◆ u_threshold

final double javolution.lang.MathLib.u_threshold = -7.45133219101941108420e+02
staticpackage

Definition at line 1392 of file MathLib.java.

Referenced by javolution.lang.MathLib._ieee754_exp().

◆ zero

final double javolution.lang.MathLib.zero = 0.0
staticpackage

Definition at line 1242 of file MathLib.java.

Referenced by javolution.lang.MathLib._ieee754_log().


The documentation for this class was generated from the following file:
javolution.lang.MathLib.Lg1
static final double Lg1
Definition: MathLib.java:1234
javolution.lang.MathLib.Lg3
static final double Lg3
Definition: MathLib.java:1236
javolution.lang.MathLib.POW5_INT
static final int[] POW5_INT
Definition: MathLib.java:351
javolution.lang.MathLib.Lg6
static final double Lg6
Definition: MathLib.java:1239
javolution.lang.MathLib.log
static double log(double x)
Definition: MathLib.java:859
javolution.lang.MathLib.toLongPow2
static long toLongPow2(double d, int n)
Definition: MathLib.java:366
javolution.lang.MathLib.toDoublePow2
static double toDoublePow2(long m, int n)
Definition: MathLib.java:203
javolution.lang.MathLib.ln2_lo
static final double ln2_lo
Definition: MathLib.java:1232
javolution.lang.MathLib.ln2_hi
static final double ln2_hi
Definition: MathLib.java:1231
javolution.lang.MathLib.bitLength
static int bitLength(int i)
Definition: MathLib.java:38
javolution.lang.MathLib.P4
static final double P4
Definition: MathLib.java:1401
javolution.lang.MathLib.NaN
static final double NaN
Definition: MathLib.java:609
javolution.lang.MathLib.P5
static final double P5
Definition: MathLib.java:1402
javolution.lang.MathLib.Lg2
static final double Lg2
Definition: MathLib.java:1235
javolution.lang.MathLib.aT
static final double aT[]
Definition: MathLib.java:1094
javolution.lang.MathLib.one
static final double one
Definition: MathLib.java:1107
javolution.lang.MathLib.invln2
static final double invln2
Definition: MathLib.java:1397
javolution.lang.MathLib.floor
static double floor(double x)
Definition: MathLib.java:692
javolution.lang.MathLib.ln2HI
static final double ln2HI[]
Definition: MathLib.java:1393
javolution.lang.MathLib.Lg4
static final double Lg4
Definition: MathLib.java:1237
javolution.lang.MathLib.u_threshold
static final double u_threshold
Definition: MathLib.java:1392
javolution.lang.MathLib.BIT_LENGTH
static final byte[] BIT_LENGTH
Definition: MathLib.java:47
javolution.lang.MathLib.ln2LO
static final double ln2LO[]
Definition: MathLib.java:1395
javolution.lang.MathLib.atanlo
static final double atanlo[]
Definition: MathLib.java:1088
javolution.lang.MathLib.two54
static final double two54
Definition: MathLib.java:1233
javolution.lang.MathLib.digitLength
static int digitLength(int i)
Definition: MathLib.java:161
javolution.lang.MathLib.toLongPow10
static long toLongPow10(double d, int n)
Definition: MathLib.java:400
javolution.lang.MathLib.Lg7
static final double Lg7
Definition: MathLib.java:1240
javolution.lang.MathLib.floorLog2
static int floorLog2(double d)
Definition: MathLib.java:526
javolution.lang.MathLib.MASK_32
static final long MASK_32
Definition: MathLib.java:349
javolution.lang.MathLib.P3
static final double P3
Definition: MathLib.java:1400
javolution.lang.MathLib.Lg5
static final double Lg5
Definition: MathLib.java:1238
javolution.lang.MathLib.P1
static final double P1
Definition: MathLib.java:1398
javolution.lang.MathLib.toDoublePow10
static double toDoublePow10(long m, int n)
Definition: MathLib.java:240
javolution.lang.MathLib.exp
static double exp(double x)
Definition: MathLib.java:846
javolution.lang.MathLib.atanhi
static final double atanhi[]
Definition: MathLib.java:1082
javolution.lang.MathLib.MathLib
MathLib()
Definition: MathLib.java:25
javolution.lang.MathLib.LOG2_DIV_LOG10
static final double LOG2_DIV_LOG10
Definition: MathLib.java:559
javolution.lang.MathLib.P2
static final double P2
Definition: MathLib.java:1399
javolution.lang.MathLib.twom1000
static final double twom1000
Definition: MathLib.java:1390
javolution.lang.MathLib.zero
static final double zero
Definition: MathLib.java:1242
javolution.lang.MathLib.pow
static double pow(double x, double y)
Definition: MathLib.java:885
javolution.lang.MathLib.halF
static final double halF[]
Definition: MathLib.java:1389
javolution.lang.MathLib.MASK_63
static final long MASK_63
Definition: MathLib.java:347
javolution.lang.MathLib.PI
static final double PI
Definition: MathLib.java:569
javolution.lang.MathLib.HALF_PI
static final double HALF_PI
Definition: MathLib.java:574
javolution.lang.MathLib.o_threshold
static final double o_threshold
Definition: MathLib.java:1391
javolution.lang.MathLib.INV_LOG10
static double INV_LOG10
Definition: MathLib.java:875
javolution.lang.MathLib.huge
static final double huge
Definition: MathLib.java:1107