Remove real type

Steven Schveighoffer schveiguy at yahoo.com
Thu Apr 22 12:19:31 PDT 2010


On Thu, 22 Apr 2010 14:50:36 -0400, Bill Baxter <wbaxter at gmail.com> wrote:

> On Thu, Apr 22, 2010 at 11:27 AM, BCS <none at anon.com> wrote:
>> Hello Bill,
>>
>>> Seems to me the only use is to
>>> preserve a few more bits in intermediate computations.
>>
>> There are some cases where you simply want to keep as much precision as  
>> you
>> can. In those cases variable precision floats aren't any better of a
>> solution as you would just turn them up as far as you can without
>> unacceptable cost elsewhere.
>
> So what's the advice you would you give to Joe coder about when to use  
> 'real'?
> My argument is that it is probably something like "if you don't know
> why you need it then you probably don't need it".  And I suspect very
> few people actually need it.  But as is, it looks like something that
> one ought to use.  It has the shortest name of all the floating point
> types.  And the description sounds pretty good -- more precision,
> hardware supported.  Wow!  Why wouldn't I want that?  But the fact is
> that most people will never need it.  And Bearophile listed some good
> reasons why not to use it in general circumstances.

Most cases where real turns out a different result than double are  
floating point error related.

For example, something that converges with doubles may not converge with  
reals, resulting in an infinite loop and a perceived difference where  
reals are seen as 'bad'.  However, the problem really is that reals have  
exposed a flaw in your algorithm where by the right circumstances, the  
double version worked.

I also find bearophile's requirement to be able to check that a D program  
outputs the same exact floating point digits as a C program ridiculous.

IMO, there is no benefit to using doubles over reals except for storage  
space.  And that is not a good reason to get rid of real.  You see a  
benefit (more precision) for a cost (more storage).  It's not a confusing  
concept.

-Steve



More information about the Digitalmars-d mailing list