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

Function makeRational

stackgl_modules/index.js:2175–2223  ·  view source on GitHub ↗
(numer, denom)

Source from the content-addressed store, hash-verified

2173module.exports = makeRational
2174
2175function makeRational(numer, denom) {
2176 if(isRat(numer)) {
2177 if(denom) {
2178 return div(numer, makeRational(denom))
2179 }
2180 return [numer[0].clone(), numer[1].clone()]
2181 }
2182 var shift = 0
2183 var a, b
2184 if(isBN(numer)) {
2185 a = numer.clone()
2186 } else if(typeof numer === 'string') {
2187 a = str2bn(numer)
2188 } else if(numer === 0) {
2189 return [num2bn(0), num2bn(1)]
2190 } else if(numer === Math.floor(numer)) {
2191 a = num2bn(numer)
2192 } else {
2193 while(numer !== Math.floor(numer)) {
2194 numer = numer * Math.pow(2, 256)
2195 shift -= 256
2196 }
2197 a = num2bn(numer)
2198 }
2199 if(isRat(denom)) {
2200 a.mul(denom[1])
2201 b = denom[0].clone()
2202 } else if(isBN(denom)) {
2203 b = denom.clone()
2204 } else if(typeof denom === 'string') {
2205 b = str2bn(denom)
2206 } else if(!denom) {
2207 b = num2bn(1)
2208 } else if(denom === Math.floor(denom)) {
2209 b = num2bn(denom)
2210 } else {
2211 while(denom !== Math.floor(denom)) {
2212 denom = denom * Math.pow(2, 256)
2213 shift += 256
2214 }
2215 b = num2bn(denom)
2216 }
2217 if(shift > 0) {
2218 a = a.ushln(shift)
2219 } else if(shift < 0) {
2220 b = b.ushln(-shift)
2221 }
2222 return rationalize(a, b)
2223}
2224
2225
2226/***/ }),

Callers

nothing calls this directly

Calls 5

isRatFunction · 0.85
divFunction · 0.85
isBNFunction · 0.85
num2bnFunction · 0.85
rationalizeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…