Bug creation and email sending has been disabled, file new bugs at gcc.gnu.org/bugzilla
Bug 14 - ARM: runnable/testmath.d Arm not precise enough?
Summary: ARM: runnable/testmath.d Arm not precise enough?
Status: RESOLVED FIXED
Alias: None
Product: GDC
Classification: Unclassified
Component: gdc (show other bugs)
Version: development
Hardware: ARM Linux
: --- trivial
Assignee: Johannes Pfau
URL:
Depends on:
Blocks:
 
Reported: 2012-09-25 12:09 CEST by Johannes Pfau
Modified: 2012-10-01 15:12 CEST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Johannes Pfau 2012-09-25 12:09:01 CEST
----
equals: x = 0.523599
equals: y = 0.523599
equals: ndigits = 16
bufx = '0.5235987755982989'
bufy = '0.5235987755982988'
core.exception.AssertError@runnable/testmath.d(134): Assertion failure
----

Seems the floating point calculations (or fp to string conversion) on ARM (or at least on the Raspberry Pi) are not precise enough to pass the tests in testmath.d.

What should be done about this?
1. Lower required precision for all platforms
2. Special case ARM to lower precision
3. ?
Comment 1 Johannes Pfau 2012-09-25 12:13:08 CEST
What is this test supposed to do?

----
    int exp;
    real mantissa = frexp(123.456, exp);
    assert(equals(mantissa * pow(2.0L, cast(real)exp), 123.456, 19));
----
equals: x = 67.456
equals: y = 123.456
equals: ndigits = 19
bufx = '67.45600000000000307'
bufy = '123.4560000000000031'
core.exception.AssertError@testmath.d(170): Assertion failure
Comment 2 Iain Buclaw 2012-09-25 16:53:49 CEST
An alternate option could be to rethink the codegen for floating comparisons in GDC overall, as certain floating point comparisons fail in GDC x86/x86_64 too.


Problem:
Simply doing (A == B) is not correct.


Possible solution:
The comparison with an epsilon value is what most tends to be done in game programming.

However the following:
(diff = A - B, (diff < EPSILON) && (-diff > EPSILON)))

Is a bit of wasted processing for something that should be fast, yet effective.


Here's an interesting read-up: http://realtimecollisiondetection.net/blog/?p=89


Regards
Iain
Comment 3 Johannes Pfau 2012-09-27 17:35:31 CEST
Not sure if we should do anything about this in the compiler. I wonder what dmd does?

Anyway:
https://github.com/D-Programming-Language/dmd/pull/1146
http://forum.dlang.org/thread/k3v614$2882$1@digitalmars.com

hopefully fixed soon in upstream
Comment 4 Iain Buclaw 2012-09-27 17:38:07 CEST
Cool beans.

By the way, if there's anything you need downstreaming to gdc, just send it my way.

Thanks.
Comment 5 Johannes Pfau 2012-10-01 15:12:20 CEST
@Iain sure, I'll do that. But most of those fixes are just errors in the test suite, not really errors in the library/compiler, so that stuff can wait till the 2.061 merge.

testmath.d has been removed from the test suite in upstream dmd (2.061), so I'm closing this. I hope Don won't forget the fix for frexp though.
https://github.com/D-Programming-Language/dmd/commit/77ad29c6b38897881e849d6f80165921febe1293