2023-01-22 01:34:57 +00:00
|
|
|
import {configDependency} from '../core/Config.js'
|
|
|
|
import {Signature} from '../interfaces/type.js'
|
2023-10-17 21:54:10 +00:00
|
|
|
import {$reflect} from '../interfaces/type.js'
|
2023-01-22 01:34:57 +00:00
|
|
|
|
|
|
|
const DBL_EPSILON = Number.EPSILON || 2.2204460492503130808472633361816E-16
|
|
|
|
|
|
|
|
export const equal =
|
|
|
|
(dep: configDependency): Signature<'equal', number> =>
|
|
|
|
(x, y) => {
|
|
|
|
const eps = dep.config.epsilon
|
|
|
|
if (eps === null || eps === undefined) return x === y
|
|
|
|
if (x === y) return true
|
|
|
|
if (isNaN(x) || isNaN(y)) return false
|
|
|
|
|
|
|
|
if (isFinite(x) && isFinite(y)) {
|
|
|
|
const diff = Math.abs(x - y)
|
|
|
|
if (diff < DBL_EPSILON) return true
|
|
|
|
return diff <= Math.max(Math.abs(x), Math.abs(y)) * eps
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
2023-10-17 21:54:10 +00:00
|
|
|
$reflect!([equal])
|