| 5 | export const NUMBER_OPTIONS = ['number', 'BigNumber', 'bigint', 'Fraction'] // valid values for option number |
| 6 | |
| 7 | export function configFactory (config, emit) { |
| 8 | /** |
| 9 | * Set configuration options for math.js, and get current options. |
| 10 | * Will emit a 'config' event, with arguments (curr, prev, changes). |
| 11 | * |
| 12 | * This function is only available on a mathjs instance created using `create`. |
| 13 | * |
| 14 | * Syntax: |
| 15 | * |
| 16 | * math.config(config: Object): Object |
| 17 | * |
| 18 | * Examples: |
| 19 | * |
| 20 | * import { create, all } from 'mathjs' |
| 21 | * |
| 22 | * // create a mathjs instance |
| 23 | * const math = create(all) |
| 24 | * |
| 25 | * math.config().number // outputs 'number' |
| 26 | * math.evaluate('0.4') // outputs number 0.4 |
| 27 | * math.config({number: 'Fraction'}) |
| 28 | * math.evaluate('0.4') // outputs Fraction 2/5 |
| 29 | * |
| 30 | * @param {Object} [options] Available options: |
| 31 | * {number} relTol |
| 32 | * Minimum relative difference between two |
| 33 | * compared values, used by all comparison functions. |
| 34 | * {number} absTol |
| 35 | * Minimum absolute difference between two |
| 36 | * compared values, used by all comparison functions. |
| 37 | * {string} matrix |
| 38 | * A string 'Matrix' (default) or 'Array'. |
| 39 | * {string} number |
| 40 | * A string 'number' (default), 'BigNumber', 'bigint', or 'Fraction' |
| 41 | * {number} precision |
| 42 | * The number of significant digits for BigNumbers. |
| 43 | * Not applicable for Numbers. |
| 44 | * {string} parenthesis |
| 45 | * How to display parentheses in LaTeX and string |
| 46 | * output. |
| 47 | * {string} randomSeed |
| 48 | * Random seed for seeded pseudo random number generator. |
| 49 | * Set to null to randomly seed. |
| 50 | * @return {Object} Returns the current configuration |
| 51 | */ |
| 52 | function _config (options) { |
| 53 | if (options) { |
| 54 | if (options.epsilon !== undefined) { |
| 55 | // this if is only for backwards compatibility, it can be removed in the future. |
| 56 | console.warn('Warning: The configuration option "epsilon" is deprecated. Use "relTol" and "absTol" instead.') |
| 57 | const optionsFix = clone(options) |
| 58 | optionsFix.relTol = options.epsilon |
| 59 | optionsFix.absTol = options.epsilon * 1e-3 |
| 60 | delete optionsFix.epsilon |
| 61 | return _config(optionsFix) |
| 62 | } |
| 63 | |
| 64 | if (options.legacySubset === true) { |