Skip to content

Commit

Permalink
Added warning for config.epsilon
Browse files Browse the repository at this point in the history
  • Loading branch information
dvd101x committed Apr 12, 2024
1 parent e7eb46e commit 8fc4c4d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/core/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { create, all } from 'mathjs'
// create a mathjs instance with configuration
const config = {
relTol: 1e-12,
absTol: 1e.15,
absTol: 1e-15,
matrix: 'Matrix',
number: 'number',
precision: 64,
Expand Down
32 changes: 21 additions & 11 deletions src/core/function/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,33 @@ export function configFactory (config, emit) {
*/
function _config (options) {
if (options) {
const prev = mapObject(config, clone)
if (options.epsilon !== undefined) {
// backwards compatibility
console.warn('Warning: The configuration option "epsilon" is deprecated. Use "relTol" and "absTol" instead.')
const optionsFix = mapObject(options, clone)
optionsFix.relTol = options.epsilon
optionsFix.absTol = options.epsilon * 1e-3
delete optionsFix.epsilon
return _config(optionsFix)
} else {
const prev = mapObject(config, clone)

// validate some of the options
validateOption(options, 'matrix', MATRIX_OPTIONS)
validateOption(options, 'number', NUMBER_OPTIONS)
// validate some of the options
validateOption(options, 'matrix', MATRIX_OPTIONS)
validateOption(options, 'number', NUMBER_OPTIONS)

// merge options
deepExtend(config, options)
// merge options
deepExtend(config, options)

const curr = mapObject(config, clone)
const curr = mapObject(config, clone)

const changes = mapObject(options, clone)
const changes = mapObject(options, clone)

// emit 'config' event
emit('config', curr, prev, changes)
// emit 'config' event
emit('config', curr, prev, changes)

return curr
return curr
}
} else {
return mapObject(config, clone)
}
Expand Down

0 comments on commit 8fc4c4d

Please sign in to comment.