Replies: 4 comments
-
Here are the
Sourceconst M = Math; // To reduce the minified code size
const fallbackFn = () => 0;
function getMathFingerprint() {
// Native operations
const acos = M.acos || fallbackFn;
const acosh = M.acosh || fallbackFn;
const asin = M.asin || fallbackFn;
const asinh = M.asinh || fallbackFn;
const atanh = M.atanh || fallbackFn;
const atan = M.atan || fallbackFn;
const sin = M.sin || fallbackFn;
const sinh = M.sinh || fallbackFn;
const cos = M.cos || fallbackFn;
const cosh = M.cosh || fallbackFn;
const tan = M.tan || fallbackFn;
const tanh = M.tanh || fallbackFn;
const exp = M.exp || fallbackFn;
const expm1 = M.expm1 || fallbackFn;
const log1p = M.log1p || fallbackFn;
// Operation polyfills
const powPI = (value) => M.pow(M.PI, value);
const acoshPf = (value) => M.log(value + M.sqrt(value * value - 1));
const asinhPf = (value) => M.log(value + M.sqrt(value * value + 1));
const atanhPf = (value) => M.log((1 + value) / (1 - value)) / 2;
const sinhPf = (value) => M.exp(value) - 1 / M.exp(value) / 2;
const coshPf = (value) => (M.exp(value) + 1 / M.exp(value)) / 2;
const expm1Pf = (value) => M.exp(value) - 1;
const tanhPf = (value) => (M.exp(2 * value) - 1) / (M.exp(2 * value) + 1);
const log1pPf = (value) => M.log(1 + value);
// Note: constant values are empirical
return {
acos: acos(0.123124234234234242),
acosh: acosh(1e308),
acoshPf: acoshPf(1e154), // 1e308 will not work for polyfill
asin: asin(0.123124234234234242),
asinh: asinh(1),
asinhPf: asinhPf(1),
atanh: atanh(0.5),
atanhPf: atanhPf(0.5),
atan: atan(0.5),
sin: sin(-1e300),
sinh: sinh(1),
sinhPf: sinhPf(1),
cos: cos(10.000000000123),
cosh: cosh(1),
coshPf: coshPf(1),
tan: tan(-1e300),
tanh: tanh(1),
tanhPf: tanhPf(1),
exp: exp(1),
expm1: expm1(1),
expm1Pf: expm1Pf(1),
log1p: log1p(10),
log1pPf: log1pPf(10),
powPI: powPI(-100),
};
}
(globalThis.print || console.log)(
Object.entries(getMathFingerprint())
.map(([key, value]) => `${key}= ${value}`)
.join("\n")
); Engine versions
|
Beta Was this translation helpful? Give feedback.
-
Those are differences by engine, what about by instruction-set architecture? Are those engine differences all on the same architecture? Which? fwiw, I am more surprised to see engine differences than I would be to see architecture differences. |
Beta Was this translation helpful? Give feedback.
-
Even more surprising than by engine or by architecture. What OS were these on? |
Beta Was this translation helpful? Give feedback.
-
Relevant: tc39/ecma262#3347 |
Beta Was this translation helpful? Give feedback.
-
Apparently the floating point
Math
functions do not return the same results on all platform / engines / architectures.At this point we should probably also verify that all operations are actually fully deterministic on the same environment.
Some pointers:
Beta Was this translation helpful? Give feedback.
All reactions