Upload
nodejsfoundation
View
86
Download
3
Embed Size (px)
Citation preview
STANDARD LIBRARY
ES5acosasinatanatan2cossintan
absexplog (ln)powsqrt
ceilfloorround
maxminrandom
ES2015/ES6acoshasinhatanhcoshsinhtanh
signcbrtexpm1log10log1plog2
froundtrunc
hypotclz32imul
COMPARISON
GOLANGAbsAcoshAsinAsinhAtanAtan2AtanhCbrtCeilCopysign
CosCoshDimErfErfcExpExp2Expm1Float32bitsFloat64bits
FloorFrexpGammaHypotIlogbJ0J1JnLdexpLgamma
LogLog10Log1pLog2LogbMaxMinModModfNexta�er
GOLANGNextA�er32PowPow10SignbitSinSincosSinhSqrtTanTanh
TruncY0Y1YnExpFloat64Float64IntInt63NormFloat64Perm
Uint32Zipf(Complex)(Big)
SO WHAT?
BUGS
V8 AND NODENode EOL V8 Release
0.10.44 10-2016 3.14.5.9 05-2013
0.12.17 01-2017 3.28.71.19 11-2014
4.6.2 04-2018 4.5.103.42 08-2015
5.12.0 07-2016 4.6.85.32 11-2015
6.9.1 04-2019 5.1.281.84 07-2016
7.2.0 07-2017 5.4.500.43 11-2016
Math.sin/Math.cosvar x = Math.pow( 2, 120 ); // returns 1.329227995784916e+36
var y = Math.sin( x ); // returns: -0.8783788442551665 // expected: 0.377820109360752
y = Math.cos( x ); // returns: 0.47796506772457525 // expected: -0.9258790228548378
Node v0.10
NaNvar nan1 = 0.0 / 0.0; var nan2 = Number.POSITIVE_INFINITY / Number.POSITIVE_INFINITY;
var arr = [ nan1, nan2 ]; var FLOAT64_VIEW = new Float64Array( arr ); var INT32_VIEW = new Int32Array( FLOAT64_VIEW.buffer );
var isnan1 = ( FLOAT64_VIEW[0] !== FLOAT64_VIEW[0] ); // returns true
var isnan2 = ( FLOAT64_VIEW[1] !== FLOAT64_VIEW[1] ); // returns true
var bool = ( nan1 !== nan2 ); // returns true
Node v0.12 Node v4 Node v6 Node v7Node v0.10*
Math.powvar x = Math.pow( 10, 308 ); // returns: 1.0000000000000006e+308 // expected: 1.0e+308
Node v0.10+
Algorithmfunction pow( x, y ) { var m = x; var n = y; var p = 1; while ( n !== 0 ) { if ( ( n & 1 ) !== 0 ) { p *= m; } m *= m; if ( ( n & 2 ) !== 0 ) { p *= m; } m *= m; n >>= 2; } return p;
Math.atanhvar y = Math.atanh( 1.0e-10 ); // returns: 1.000000082640371e-10 // expected: 1.0e-10
Node v0.12 Node v4 Node v6
Math.acoshvar y = Math.acosh( 1.0 + 1.0e-10 ); // returns: 0.000014142136208733941 // expected: 0.000014142136208675862
Node v0.12 Node v4 Node v6
Math.asinhvar y = Math.asinh( 1.0e-50 ); // returns: 0.0 // expected: 1.0e-50
y = Math.asinh( 1.0e200 ); // returns +infinity // expected: 461.2101657793691
Node v0.12 Node v4 Node v6
Algorithmfunction asinh( x ) { if ( x === 0 || !isFinite( x ) ) { return x; } if ( x > 0 ) { return Math.log( x + Math.sqrt( x*x + 1 ) ); } return -Math.log( -x + Math.sqrt( x*x + 1 ) ); }
Algorithmfunction asinh( x ) { var sgn; var xx; var t; if ( isnan( x ) || isinfinite( x ) ) { return x; } if ( x < 0.0 ) { x = -x; sgn = true; } // Case: |x| < 2**-28 if ( x < NEAR_ZERO ) { t = x; } // Case: |x| > 2**28
Math.expvar y = Math.exp( 100.0 ); // returns: 2.6881171418161485e+43 // expected: 2.6881171418161356e+43
Node v0.12 Node v4 Node v6
Math.randomuint32_t state0 = 1; uint32_t state1 = 2; uint32_t mwc1616() { state0 = 18030 * (state0 & 0xffff) + (state0 >> 16); state1 = 30903 * (state1 & 0xffff) + (state1 >> 16); return state0 << 16 + (state1 & 0xffff); }
Node v0.10 Node v0.12 Node v4
Examplevar ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'
function randomString( length ) { var randint; var str; var i;
str = ''; for ( i = 0; i < length; i++ ) { randint = Math.floor( Math.random() * ALPHABET.length ); str += ALPHABET.substring( randint, randint+1 ); } return str; }
Betable
V8 blog
JavaScript
UnderspecificationCross-browser variabilityNo single codebaseVersioningRequired shims
GlobalsTestingNo golden algorithmsTimescaleTrust
Community
Polyfillsvar isFinite = require( 'is-finite' );
module.exports = function asinh( x ) { if ( x === 0 || !isFinite( x ) ) { return x; } return x < 0 ? -asinh( -x ) : Math.log( x + Math.sqrt( x*x + 1 ) );}
Librariesfunction asinh( x ) { return Math.log( Math.sqrt( x*x + 1 ) + x ); }
:(
github.com/stdlib-js/stdlib
Opportunities
Get Involved!
AdvocateInt64/Uint64Int128/Uint128Typed Objects (complex)SIMD (long)
ParallelismGPGPUBigFloat/BigInt
Thank you! / Athan Reines @kgryte
https://github.com/stdlib-js/stdlib
APPENDIX
WHAT CAN BE DONE AT THESPECIFICATION LEVEL?
(and bitwise ops)Int64Typed ObjectsWebCLSIMD (long)Parallel ComputingOperator OverloadingWeb Assembly
INTEGER SUPPORTdiscussiongistInt64 in R
TYPED OBJECTSspecexplainertyped data structures in Go
WEBCLnode-opencl
SIMDpolyfillIntel announcementMDNpresentation
PARALLEL COMPUTINGData parallelismTask parallelismSchedulerLock-free programmingShared Memory Web Workers
OPERATOR OVERLOADINGoperator-overloading-jspaper.jspaper.js source
THE END