Why are some casts from floating point to integral done differently

Aldo Nunez aldonunez1 at gmail.com
Mon Mar 15 11:39:54 PDT 2010


Don Wrote:

> The cast(uint) case is clearly a bug. Please file it in Bugzilla.

I'll file a bug, but...

> This happens because there are no built-in functions for converting from 
> float to unsigned. Values between int.max and uint.max need to be 
> treated specially.
> 
> 

You're right, but why isn't it done for (float, double -> ulong) like it's done for (real -> ulong), where it's a simple conversion to long plus a fixup. It's not like (float -> real -> ulong) will introduce more precise non-zero bits (or will it?).

Then there's the case of (float, double, real -> uint). Why isn't this done like (float, double, real -> ushort), where a simple conversion to int is done, and then the result is truncated to ushort? Wouldn't it work the same to do a simple conversion to long, and then truncate the result to uint?

I'm just trying to understand why these simple, yet seemingly just as accurate methods weren't used.



More information about the Digitalmars-d mailing list