-
-
Notifications
You must be signed in to change notification settings - Fork 693
Expand file tree
/
Copy pathmath.ts
More file actions
20 lines (18 loc) · 675 Bytes
/
math.ts
File metadata and controls
20 lines (18 loc) · 675 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
* @fileoverview Various math utility.
* @license Apache-2.0
*/
/** Tests if `x` is a power of two. */
export function isPowerOf2(x: i32): bool {
return x != 0 && (x & (x - 1)) == 0;
}
export function accuratePow64(x: f64, y: f64): f64 {
if (!ASC_TARGET) { // ASC_TARGET == JS
// Engines like V8, WebKit and SpiderMonkey uses powi fast path if exponent is integer
// This speculative optimization leads to loose precisions like 10 ** -5 != 1e-5 anymore
// and introduces inconsistencies between different engines and versions
// For avoid this behavior we using bootstrap f64_pow function.
return f64_pow(x, y);
}
return Math.pow(x, y);
}