This repository was archived by the owner on Jun 5, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 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;
2424
2525exports . floor = Math . floor ;
2626
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+
2749exports . trunc = Math . trunc || function ( n ) {
2850 return n < 0 ? Math . ceil ( n ) : Math . floor ( n ) ;
2951} ;
Original file line number Diff line number Diff line change @@ -36,6 +36,9 @@ foreign import exp :: Number -> Number
3636-- | Returns the largest integer not larger than the argument.
3737foreign import floor :: Number -> Number
3838
39+ -- | Returns the result of the C-like 32-bit multiplication of the two arguments.
40+ foreign import imul :: Int -> Int -> Int
41+
3942-- | Returns the natural logarithm of a number.
4043foreign import log :: Number -> Number
4144
You can’t perform that action at this time.
0 commit comments