3 months of waiting...
Walter Bright
newshound2 at digitalmars.com
Sat Feb 8 01:52:25 UTC 2020
On 2/7/2020 12:00 PM, berni44 wrote:
> The
> difficult thing is to get the mix of all the flags, precission, width and
> rounding right.
Of course :-)
The other problem I neglected to mention is D does not have a thorough test
suite for floating point formatting. Writing one seemed pointless as we were
relying on the C standard library to do it, and presumably the C people had
tested it properly.
This assumption did turn out to be false, at least for the transcendental
functions. Many C targets turned out to have precision problems.
A lot of algorithms really do care if 3.78612345 is more accurate than 3.78612344.
In other words, writing a better implementation is one thing, showing that it is
at least as correct as what it replaces is also necessary.
One way to shortcut that is to use an algorithm that is generally accepted by
the industry to be correct, then the problem is reduced to showing that the
algorithm is implemented correctly. (This is what I've done, for example, in the
compiler optimization that replaces divides with multiplications by a constant.)
Another way is to construct a tester that randomly generates bit patterns, then
formats the result with both sprintf and the new implementation, and they must
match exactly. Then it's a matter of how many of these test cases are run.
More information about the Digitalmars-d
mailing list