Loss of precision errors in FP conversions

Walter Bright newshound2 at digitalmars.com
Tue Apr 19 17:55:55 PDT 2011


On 4/19/2011 5:02 PM, dsimcha wrote:
> Generally I worry about D's type system becoming like the Boy Who Cried Wolf,
> where it flags so many potential errors (as opposed to things that are
> definitely errors) that people become conditioned to just put in whatever casts
> they need to shut it up. I definitely fell into that when porting some 32-bit
> code that was sloppy with size_t vs. int to 64-bit. I knew there was no way it
> was going to be a problem, because there was no way any of my arrays were going
> to be even within a few orders of magnitude of int.max, but the compiler
> insisted on nagging me about it and I reflexively just put in casts everywhere.
> A warning _may_ be appropriate, but definitely not an error.

That's definitely a worry. Having a Nagging Nellie giving false alarms on errors 
too often will:

1. cause programmers to hate D

2. lead to MORE bugs and harder to find ones, as Bruce Eckel pointed out, 
because people will put in things "just to shut up the compiler"

Hence my reluctance to add in a lot of these suggestions.

As to the specific about erroring on reducing precision, my talks with people 
who actually do write a lot of FP code for a living is NO. They don't want it. 
Losing precision in FP calculations is a fact of life, and FP programmers simply 
must understand it and deal with it. Having the compiler annoy you about it 
would be less than helpful.


More information about the Digitalmars-d mailing list