Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*jslint bitwise: true */
- 'use strict';
- (function() {
- return {
- abs: Math.abs,
- acos: Math.acos,
- asin: Math.asin,
- atan: Math.atan,
- atan2: Math.atan2,
- ceil: Math.ceil,
- cos: Math.cos,
- cosh: function(x) {
- var y = Math.exp(x);
- return (y + 1 / y) / 2;
- },
- deg: function(x) {
- return x / (Math.PI / 180);
- },
- exp: Math.exp,
- floor: Math.floor,
- fmod: function(x, y) {
- return Number((x - (Math.floor(x / y) * y)).toPrecision(8));
- },
- // Article: http://croquetweak.blogspot.com/2014/08/deconstructing-floats-frexp-and-ldexp.html
- // https://github.com/bertfreudenberg/SqueakJS/commit/e4d60ea16cc1d9868872dde6033e0bbf5166bd6f
- frexp: function(x) {
- if (x === 0.0) return 0;
- var data = new DataView(new ArrayBuffer(8));
- data.setFloat64(0, x);
- var bits = (data.getUint32(0) >>> 20) & 0x7FF;
- if (bits === 0) {
- data.setFloat64(0, x * Math.pow(2, 64));
- bits = ((data.getUint32(0) >>> 20) & 0x7FF) - 64;
- }
- var e = bits - 1022;
- var m = this.ldexp(x, -e);
- return [m, e];
- },
- huge: Infinity,
- // Article: http://croquetweak.blogspot.com/2014/08/deconstructing-floats-frexp-and-ldexp.html
- // https://github.com/bertfreudenberg/SqueakJS/commit/e4d60ea16cc1d9868872dde6033e0bbf5166bd6f
- ldexp: function(m, e) {
- return e <= 1023 ?
- m * Math.pow(2, e) :
- m * Math.pow(2, 1023) * Math.pow(2, e - 1023);
- },
- log: Math.log,
- log10: function(x) {
- return Math.log(x) / Math.LN10;
- },
- max: Math.max,
- min: Math.min,
- modf: function(x) {
- return [Math.floor(x), x % 1];
- },
- pi: Math.PI,
- pow: Math.pow,
- rad: function(x) {
- return x * (Math.PI / 180);
- },
- random: function(m, n) {
- var r = Math.random();
- var l, u;
- if (m && n) {
- l = m;
- u = n;
- return Math.floor(r * (u - l + 1) + l);
- } else if (m) {
- u = m;
- return Math.floor(r * u) + 1;
- } else {
- return r;
- }
- },
- // Does nothing
- randomseed: function(){},
- sin: Math.sin,
- sinh: function(x) {
- var y = Math.exp(x);
- return (y - 1/y) / 2;
- },
- sqrt: Math.sqrt,
- tan: Math.tan,
- tanh: function(x) {
- if(x === Infinity) {
- return 1;
- } else if(x === -Infinity) {
- return -1;
- } else {
- var y = Math.exp(2 * x);
- return (y - 1) / (y + 1);
- }
- }
- };
- }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement