MCPcopy Index your code
hub / github.com/plotly/plotly.js / roundRat

Function roundRat

stackgl_modules/index.js:2476–2503  ·  view source on GitHub ↗
(f)

Source from the content-addressed store, hash-verified

2474
2475// Round a rational to the closest float
2476function roundRat (f) {
2477 var a = f[0]
2478 var b = f[1]
2479 if (a.cmpn(0) === 0) {
2480 return 0
2481 }
2482 var h = a.abs().divmod(b.abs())
2483 var iv = h.div
2484 var x = bn2num(iv)
2485 var ir = h.mod
2486 var sgn = (a.negative !== b.negative) ? -1 : 1
2487 if (ir.cmpn(0) === 0) {
2488 return sgn * x
2489 }
2490 if (x) {
2491 var s = ctz(x) + 4
2492 var y = bn2num(ir.ushln(s).divRound(b))
2493 return sgn * (x + y * Math.pow(2, -s))
2494 } else {
2495 var ybits = b.bitLength() - ir.bitLength() + 53
2496 var y = bn2num(ir.ushln(ybits).divRound(b))
2497 if (ybits < 1023) {
2498 return sgn * y * Math.pow(2, -ybits)
2499 }
2500 y *= Math.pow(2, -1023)
2501 return sgn * y * Math.pow(2, 1023 - ybits)
2502 }
2503}
2504
2505
2506/***/ }),

Callers

nothing calls this directly

Calls 1

bn2numFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…