Public
Code
HTTP
export async function val_rSdr9CumnJ(req) {
try {
// Execute the code directly and capture its result
const result = await (async () => {
// Test for floating point precision anomalies
function testFloatingPointPrecision() {
const results = [];
// Test 1: Basic arithmetic that should equal 1
const test1 = 0.1 + 0.2 + 0.7;
results.push({
test: "Basic Arithmetic",
expected: 1,
actual: test1,
isGlitch: Math.abs(1 - test1) > Number.EPSILON
});
// Test 2: Recursive division and multiplication
let test2 = 1;
for(let i = 0; i < 10; i++) {
test2 = test2 / 3 * 3;
}
results.push({
test: "Recursive Operations",
expected: 1,
actual: test2,
isGlitch: Math.abs(1 - test2) > Number.EPSILON
});
return JSON.stringify(results, null, 2);
}
return testFloatingPointPrecision();
})();
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
dhvanil-val_rsdr9cumnj.web.val.run
Updated: November 9, 2024