MCPcopy
hub / github.com/josdejong/mathjs / normalizeFormatOptions

Function normalizeFormatOptions

src/utils/number.js:317–350  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

315 * }
316 */
317export function normalizeFormatOptions (options) {
318 // default values for options
319 let notation = 'auto'
320 let precision
321 let wordSize
322
323 if (options !== undefined) {
324 if (isNumber(options)) {
325 precision = options
326 } else if (isBigNumber(options)) {
327 precision = options.toNumber()
328 } else if (isObject(options)) {
329 if (options.precision !== undefined) {
330 precision = _toNumberOrThrow(options.precision, () => {
331 throw new Error('Option "precision" must be a number or BigNumber')
332 })
333 }
334
335 if (options.wordSize !== undefined) {
336 wordSize = _toNumberOrThrow(options.wordSize, () => {
337 throw new Error('Option "wordSize" must be a number or BigNumber')
338 })
339 }
340
341 if (options.notation) {
342 notation = options.notation
343 }
344 } else {
345 throw new Error('Unsupported type of options, number, BigNumber, or object expected')
346 }
347 }
348
349 return { notation, precision, wordSize }
350}
351
352/**
353 * Split a number into sign, coefficients, and exponent

Callers 2

formatFunction · 0.90
formatFunction · 0.85

Calls 5

isNumberFunction · 0.90
isBigNumberFunction · 0.90
isObjectFunction · 0.90
_toNumberOrThrowFunction · 0.85
toNumberMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…