-
-
Notifications
You must be signed in to change notification settings - Fork 687
Expand file tree
/
Copy pathobject.ts
More file actions
36 lines (34 loc) · 1.23 KB
/
object.ts
File metadata and controls
36 lines (34 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
export abstract class Object {
static is<T>(x: T, y: T): bool {
if (isFloat<T>()) {
// Float pointing is special we shoulr presere following identities:
// 0.0 !=-0.0
// NaN == NaN
if (sizeof<T>() == 8) {
return (
bool(u32(x != x) & u32(y != y) |
u32(reinterpret<u64>(f64(x)) == reinterpret<u64>(f64(y))))
);
} else {
return (
bool(u32(x != x) & u32(y != y) |
u32(reinterpret<u32>(f32(x)) == reinterpret<u32>(f32(y))))
);
}
}
// For references, strings, integers and booleans
return x == y;
}
// TODO: Wrapper classes like `Function<T>` override the `this` type of
// `toString`, which is covariant and hence fails to overload. Wrapper classes
// might need a different mechanism to indicate such special `this` types.
// toString(): string {
// return "[object Object]";
// }
}
// TODO: The types `Object` and `object` differ in TypeScript, in that the
// latter indicates any non-primitive type, not including `string` for example.
// The `object` type hence remains reserved for now, also to potentially address
// the above `toString` TODO in alternative ways.
// @ts-ignore: nolib
// export type object = Object;