File tree 2 files changed +115
-66
lines changed
2 files changed +115
-66
lines changed Original file line number Diff line number Diff line change 1
1
export class Object {
2
- static is < T > ( value1 : T , value2 : T ) : bool {
2
+ static is < T > ( x : T , y : T ) : bool {
3
3
if ( isFloat < T > ( ) ) {
4
- if ( value1 == value2 ) {
5
- // 0 == -0, but they are not identical
6
- if ( sizeof < T > ( ) == 8 ) {
7
- // @ts -ignore: typecast
8
- return reinterpret < u64 > ( value1 ) == reinterpret < u64 > ( value2 ) ;
9
- } else {
10
- // @ts -ignore: typecast
11
- return reinterpret < u32 > ( value1 ) == reinterpret < u32 > ( value2 ) ;
12
- }
4
+ // Float pointing is special we shoulr presere following identities:
5
+ // 0.0 !=-0.0
6
+ // NaN == NaN
7
+ if ( sizeof < T > ( ) == 8 ) {
8
+ return (
9
+ bool ( u32 ( x != x ) & u32 ( y != y ) |
10
+ u32 ( reinterpret < u64 > ( f64 ( x ) ) == reinterpret < u64 > ( f64 ( y ) ) ) )
11
+ ) ;
12
+ } else {
13
+ return (
14
+ bool ( u32 ( x != x ) & u32 ( y != y ) |
15
+ u32 ( reinterpret < u32 > ( f32 ( x ) ) == reinterpret < u32 > ( f32 ( y ) ) ) )
16
+ ) ;
13
17
}
14
- // NaN != NaN, but they are identical.
15
- // @ts -ignore: typecast
16
- return bool ( i32 ( isNaN ( value1 ) ) & i32 ( isNaN ( value2 ) ) ) ;
17
18
}
18
19
// For references, strings, integers and booleans
19
- return value1 == value2 ;
20
+ return x == y ;
20
21
}
21
22
}
You can’t perform that action at this time.
0 commit comments