-
Notifications
You must be signed in to change notification settings - Fork 19
Conversation
src/Math.js
Outdated
}; | ||
|
||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul | ||
function emulatedImul(a) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't line 27 ensure that it will be used in environments like Internet Explorer that don't have native imul
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've fixed up some of the jshint
complaints on this... But the ones regarding the bitwise operations seem strange to me. I'll try add a comment in to disable those.
src/Math.js
Outdated
}; | ||
|
||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul | ||
function emulatedImul(a) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't line 27 ensure that it will be used in environments like Internet Explorer that don't have native imul
?
Sorry, somehow I missed where your emulated function was used. I don't know how well it will play with DCE though, we might need to combine them. I'm not sure if we should bake in a polyfill or let the user choose one though, especially since I don't know the license of that code. |
I think it would be best to include this polyfill; if a better polyfill does exist we can always update this later. Not dealing with this here will result in a poor UX for devs who need to support IE, I think. The code is public domain; see https://developer.mozilla.org/en-US/docs/MDN/About#Copyrights_and_licenses:
The |
Okay, thanks Harry. Sounds good to me then, assuming we can check that DCE works, or modify if necessary. |
Okay, I've convinced |
Yes, you would need to reference it from some separate entry point, I think. |
I've created a branch with a main = logShow $ 3 `imul` 5 I've pasted the output of (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
// Generated by purs bundle 0.11.7
var PS = {};
(function(exports) {
"use strict";
exports.log = function (s) {
return function () {
console.log(s);
return {};
};
};
})(PS["Control.Monad.Eff.Console"] = PS["Control.Monad.Eff.Console"] || {});
(function(exports) {
"use strict";
exports.showIntImpl = function (n) {
return n.toString();
};
})(PS["Data.Show"] = PS["Data.Show"] || {});
(function(exports) {
// Generated by purs version 0.11.7
"use strict";
var $foreign = PS["Data.Show"];
var Show = function (show) {
this.show = show;
};
var showInt = new Show($foreign.showIntImpl);
var show = function (dict) {
return dict.show;
};
exports["Show"] = Show;
exports["show"] = show;
exports["showInt"] = showInt;
})(PS["Data.Show"] = PS["Data.Show"] || {});
(function(exports) {
// Generated by purs version 0.11.7
"use strict";
var $foreign = PS["Control.Monad.Eff.Console"];
var Control_Monad_Eff = PS["Control.Monad.Eff"];
var Data_Show = PS["Data.Show"];
var Data_Unit = PS["Data.Unit"];
var logShow = function (dictShow) {
return function (a) {
return $foreign.log(Data_Show.show(dictShow)(a));
};
};
exports["logShow"] = logShow;
})(PS["Control.Monad.Eff.Console"] = PS["Control.Monad.Eff.Console"] || {});
(function(exports) {
"use strict";
function nativeImul(a) {
return function (b) {
return Math.imul(a, b);
};
}
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul
function emulatedImul(a) {
/*jshint bitwise: false*/
return function (b) {
var ah = a >>> 16 & 0xffff;
var al = a & 0xffff;
var bh = b >>> 16 & 0xffff;
var bl = b & 0xffff;
// the shift by 0 fixes the sign on the high part
// the final |0 converts the unsigned value into a signed value
return al * bl + (ah * bl + al * bh << 16 >>> 0) | 0;
};
}
exports.imul = Math.imul ? nativeImul : emulatedImul;
})(PS["Math"] = PS["Math"] || {});
(function(exports) {
// Generated by purs version 0.11.7
"use strict";
var $foreign = PS["Math"];
exports["imul"] = $foreign.imul;
})(PS["Math"] = PS["Math"] || {});
(function(exports) {
// Generated by purs version 0.11.7
"use strict";
var Control_Monad_Eff = PS["Control.Monad.Eff"];
var Control_Monad_Eff_Console = PS["Control.Monad.Eff.Console"];
var Data_Function = PS["Data.Function"];
var Data_Show = PS["Data.Show"];
var $$Math = PS["Math"];
var Prelude = PS["Prelude"];
var main = Control_Monad_Eff_Console.logShow(Data_Show.showInt)($$Math.imul(3)(5));
exports["main"] = main;
})(PS["Main"] = PS["Main"] || {});
PS["Main"].main();
},{}]},{},[1]); |
I'm fine with this then. Anyone else have comments? |
Perhaps it should say in the docs that the |
No description provided.