Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions std/assembly/object.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
export class Object {
static is<T>(value1: T, value2: T): bool {
static is<T>(x: T, y: T): bool {
if (isFloat<T>()) {
if (value1 == value2) {
// 0 == -0, but they are not identical
if (sizeof<T>() == 8) {
// @ts-ignore: typecast
return reinterpret<u64>(value1) == reinterpret<u64>(value2);
} else {
// @ts-ignore: typecast
return reinterpret<u32>(value1) == reinterpret<u32>(value2);
}
// 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))))
);
}
// NaN != NaN, but they are identical.
// @ts-ignore: typecast
return bool(i32(isNaN(value1)) & i32(isNaN(value2)));
}
// For references, strings, integers and booleans
return value1 == value2;
return x == y;
}
}
Loading