Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

two-product

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

two-product - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

12

package.json
{
"name": "two-product",
"version": "1.0.0",
"version": "1.0.1",
"description": "Multiplies two floating point numbers together producing a non-overlapping increasing sequence of floats",

@@ -9,9 +9,9 @@ "main": "two-product.js",

},
"dependencies": {
"dependencies": {},
"devDependencies": {
"tape": "^2.12.3",
"test-float-overlap": "^1.0.3"
},
"devDependencies": {
"tape": "~1.1.0"
},
"scripts": {
"test": "tap test/*.js"
"test": "tape test/*.js"
},

@@ -18,0 +18,0 @@ "repository": {

"use strict"
var twoProduct = require("../two-product.js")
var testOverlap = require("test-float-overlap")
require("tape")(function(t) {
t.same(twoProduct(1, 1), [0, 1])
t.same(twoProduct(Infinity, Infinity), [0,Infinity])
t.same(twoProduct(Infinity,1), [0,Infinity])
t.same(twoProduct(Infinity,0), [0,0])
t.same(twoProduct(Infinity,-Infinity), [0,-Infinity])
t.end()
var testValues = [
0,
-0,
-1,
1,
Math.pow(2, -52),
Math.pow(2, -53),
1.0-Math.pow(2, -53),
1.0+Math.pow(2, -52),
Math.pow(2,-500),
Math.pow(2, 500),
2,
0.5,
3,
1.5,
1.2399519200255505e-149 ]
for(var i=0; i<20; ++i) {
testValues.push(Math.random())
testValues.push(Math.random() * Math.pow(2, 1000 * Math.random() - 500))
}
for(var j=0; j<testValues.length; ++j) {
var a = testValues[j]
t.ok(a*a < Infinity, "check finite: " + a)
t.same(twoProduct(0, a), [0,0], "multiply by 0")
t.same(twoProduct(1, a), [0,a], "multiply by 1")
t.same(twoProduct(-1, a), [0,-a], "multiply by -1")
for(var k=0; k<testValues.length; ++k) {
var b = testValues[k]
var s = twoProduct(a, b)
t.ok(!testOverlap(s[0], s[1]), "overlapping")
t.ok(Math.abs(s[0]) <= Math.abs(s[1]), "increasing")
t.equals(s[1], a*b, "approximation")
var r = twoProduct(b, a)
t.same(s, r, "commutativity")
}
}
//Test expansion
t.same(twoProduct(
1.0 + Math.pow(2, -52),
1.0 + Math.pow(2, -52)),
[Math.pow(2, -104), 1.0 + Math.pow(2, -51)], "test expansion")
t.end()
})

@@ -5,3 +5,3 @@ "use strict"

var HALF_DOUBLE = (1<<26) + 1
var SPLITTER = +(Math.pow(2, 26) + 1.0)

@@ -11,25 +11,25 @@ function twoProduct(a, b, result) {

var c = HALF_DOUBLE * a
var c = SPLITTER * a
var abig = c - a
var ahi = c - abig
var alo = a - ahi
var d = HALF_DOUBLE * b
var d = SPLITTER * b
var bbig = d - b
var bhi = d - bbig
var blo = b - bhi
var err1 = x - (ahi * bhi)
var err2 = err1 - (alo * bhi)
var err3 = err2 - (ahi * blo)
var y = alo * blo - err3
if(result) {
result[0] = y || 0.0
result[1] = x || 0.0
result[0] = y
result[1] = x
return result
}
return [ y || 0.0, x || 0.0 ]
return [ y, x ]
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc