digitalmars.D.learn - Precision Error?
- WhatMeWorry` (22/22) Oct 06 float computeToFitInWindow(uint rows, uint cols)
- Sergey (2/24) Oct 06 https://dlang.org/library/std/math/operations/is_close.html
float computeToFitInWindow(uint rows, uint cols) { // code removed ... writeln(hexWidth); return hexWidth; } unittest { assert(computeToFitInWindow(1, 1) == 2.0f, "This assert failed"); assert(computeToFitInWindow(3, 3) == 0.8f, "This assert failed"); assert(computeToFitInWindow(2, 2) == 1.14286f, "This assert failed"); // Line 74 } 2 0.8 1.14286 main.d(74): [unittest] This assert failed Can someone tell me why line 74 fails? Aren't they both 1.14286? I presume it has to do with precision. Is there a technique to address this issue.
Oct 06
On Sunday, 6 October 2024 at 21:09:22 UTC, WhatMeWorry` wrote:float computeToFitInWindow(uint rows, uint cols) { // code removed ... writeln(hexWidth); return hexWidth; } unittest { assert(computeToFitInWindow(1, 1) == 2.0f, "This assert failed"); assert(computeToFitInWindow(3, 3) == 0.8f, "This assert failed"); assert(computeToFitInWindow(2, 2) == 1.14286f, "This assert failed"); // Line 74 } 2 0.8 1.14286 main.d(74): [unittest] This assert failed Can someone tell me why line 74 fails? Aren't they both 1.14286? I presume it has to do with precision. Is there a technique to address this issue.https://dlang.org/library/std/math/operations/is_close.html
Oct 06