Simplify isFinite & isNaN (#78)

This commit is contained in:
Max Graey
2018-04-18 16:14:24 +03:00
committed by Daniel Wirtz
parent 5a2f834c0d
commit a15457d8b9
13 changed files with 132 additions and 409 deletions

View File

@ -13,19 +13,11 @@ export const NaN: f64 = 0 / 0;
export const Infinity: f64 = 1 / 0;
export function isNaN<T>(value: T): bool {
return isFloat(value)
? sizeof<T>() == 32
? (reinterpret<u32>(value) & -1 >>> 1) > 0xFF << 23
: (reinterpret<u64>(value) & -1 >>> 1) > 0x7FF << 52
: false;
return value != value;
}
export function isFinite<T>(value: T): bool {
return isFloat(value)
? sizeof<T>() == 32
? (reinterpret<u32>(value) & -1 >>> 1) < 0xFF << 23
: (reinterpret<u64>(value) & -1 >>> 1) < 0x7FF << 52
: true;
return value - value == 0;
}
export declare function clz<T>(value: T): T;