Set the decision and its input
The original expression rounds a rational number, then tests absolute result≥3. Ties-to-even turns5/2 into2, so the predicate is false. Ties-away gives3 and true. The programme uses integer numerator/denominator and BigInt quotient/remainder, not a binary floating-point equality example.
| Case | Input JSON |
|---|---|
| Base test | {"numerator":5,"denominator":2,"policy":"ties-even","threshold":3} |
Run the supplied comparison
Both rounding policies are explicitly defined here. Inputs require a signed safe integer numerator, positive safe integer denominator and nonnegative safe threshold. Integer zero is stored as0. No real rule engine’s rounding default is inferred.
| Path | Output JSON |
|---|---|
| Faulty path | {"rounded":3,"predicate":true} |
| Required path | {"rounded":2,"predicate":false} |
import assert from 'node:assert/strict';
const run=function run(i,corrected=true){
if(!['ties-even','ties-away'].includes(i.policy)||!Number.isSafeInteger(i.numerator)||!Number.isSafeInteger(i.denominator)||i.denominator<1||!Number.isSafeInteger(i.threshold)||i.threshold<0)return {held:true};
const signed=BigInt(i.numerator),n=signed<0n?-signed:signed,d=BigInt(i.denominator);let q=n/d;const r=n%d;
const away=!corrected||i.policy==='ties-away';if(r*2n>d||(r*2n===d&&(away||q%2n===1n)))q++;
const rounded=Number(signed<0n?-q:q);return {rounded,predicate:Math.abs(rounded)>=i.threshold};
};
const cases=[{"input":{"numerator":5,"denominator":2,"policy":"ties-even","threshold":3},"corrected":false,"expected":{"rounded":3,"predicate":true}},{"input":{"numerator":5,"denominator":2,"policy":"ties-even","threshold":3},"corrected":true,"expected":{"rounded":2,"predicate":false}},{"input":{"numerator":-5,"denominator":2,"policy":"ties-even","threshold":3},"corrected":true,"expected":{"rounded":-2,"predicate":false}},{"input":{"numerator":-5,"denominator":2,"policy":"ties-away","threshold":3},"corrected":true,"expected":{"rounded":-3,"predicate":true}},{"input":{"numerator":51,"denominator":20,"policy":"ties-even","threshold":3},"corrected":true,"expected":{"rounded":3,"predicate":true}},{"input":{"numerator":-49,"denominator":20,"policy":"ties-even","threshold":3},"corrected":true,"expected":{"rounded":-2,"predicate":false}},{"input":{"numerator":5,"denominator":2,"policy":null,"threshold":3},"corrected":true,"expected":{"held":true}},{"input":{"numerator":5,"denominator":0,"policy":"ties-even","threshold":3},"corrected":true,"expected":{"held":true}}];
for(const test of cases){const actual=await run(test.input,test.corrected);assert.deepEqual(actual,test.expected);console.log(actual);}
Choose from the boundary evidence
Negative−5/2 distinguishes−2 from−3. Nearby51/20 and−49/20 exercise non-ties. Unknown policy or zero denominator is held.
- State the exact tie policies
- Run positive and negative boundaries
- Compare the resulting predicate
Do not invent a rounding default for an unspecified engine.
| Condition | Input JSON | Expected output JSON |
|---|---|---|
| negative exact tie | {"numerator":-5,"denominator":2,"policy":"ties-even","threshold":3} | {"rounded":-2,"predicate":false} |
| declared negative tie away | {"numerator":-5,"denominator":2,"policy":"ties-away","threshold":3} | {"rounded":-3,"predicate":true} |
| positive just above tie | {"numerator":51,"denominator":20,"policy":"ties-even","threshold":3} | {"rounded":3,"predicate":true} |
| negative just below magnitude tie | {"numerator":-49,"denominator":20,"policy":"ties-even","threshold":3} | {"rounded":-2,"predicate":false} |
| rounding policy unknown | {"numerator":5,"denominator":2,"policy":null,"threshold":3} | {"held":true} |
| zero denominator outside the rule | {"numerator":5,"denominator":0,"policy":"ties-even","threshold":3} | {"held":true} |
Does identical expression text establish the base predicate is portable?
Show the worked answer
No. The declared tie policy changes2 versus3 and therefore false versus true. Retest both signs with the agreed policy before using the predicate.