This repository was archived by the owner on Jun 5, 2022. It is now read-only.
File tree 2 files changed +25
-0
lines changed
2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,28 @@ exports.exp = Math.exp;
24
24
25
25
exports . floor = Math . floor ;
26
26
27
+ function nativeImul ( a ) {
28
+ return function ( b ) {
29
+ return Math . imul ( a , b ) ;
30
+ } ;
31
+ }
32
+
33
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul
34
+ function emulatedImul ( a ) {
35
+ /*jshint bitwise: false*/
36
+ return function ( b ) {
37
+ var ah = a >>> 16 & 0xffff ;
38
+ var al = a & 0xffff ;
39
+ var bh = b >>> 16 & 0xffff ;
40
+ var bl = b & 0xffff ;
41
+ // the shift by 0 fixes the sign on the high part
42
+ // the final |0 converts the unsigned value into a signed value
43
+ return al * bl + ( ah * bl + al * bh << 16 >>> 0 ) | 0 ;
44
+ } ;
45
+ }
46
+
47
+ exports . imul = Math . imul ? nativeImul : emulatedImul ;
48
+
27
49
exports . trunc = Math . trunc || function ( n ) {
28
50
return n < 0 ? Math . ceil ( n ) : Math . floor ( n ) ;
29
51
} ;
Original file line number Diff line number Diff line change @@ -36,6 +36,9 @@ foreign import exp :: Number -> Number
36
36
-- | Returns the largest integer not larger than the argument.
37
37
foreign import floor :: Number -> Number
38
38
39
+ -- | Returns the result of the C-like 32-bit multiplication of the two arguments.
40
+ foreign import imul :: Int -> Int -> Int
41
+
39
42
-- | Returns the natural logarithm of a number.
40
43
foreign import log :: Number -> Number
41
44
You can’t perform that action at this time.
0 commit comments