On 15 July 2013 16:54, H. S. Teoh <hsteoh@quickfur.ath.cx> wrote:
On Tue, Jul 16, 2013 at 12:04:08AM +1000, Daniel Murphy wrote:
> I would prefer to see (as either builtins or properties) a way to
> get/set the exponent/mantissa/sign of a float.
>
> eg
> float x;
> x.sign = 1;
> assert(x.exp == 123);
>
> Easily ctfeable, no need for casting, no endianness problems.
[...]

+1. IMO this is the right way to handle floating-point attributes.
Direct knowledge about the binary representation should be restricted to
the compiler as much as possible. Plus, having these attributes could
potentially be useful in other contexts than std.math.

No. You shouldn't be doing these kind of operations in normal code, you should be using normal arithmetic. If you need to know the exponent, you should use library functions like frexp().
You shouldn't be poking in the internals of a float unless you know the bit pattern exactly, and you need the extra speed.
This issue only applies to 80-bit reals on x86, this is really a very special case. Floats and doubles already allow the necessary casts.





 


T

--
The best way to destroy a cause is to defend it poorly.
_______________________________________________
dmd-internals mailing list
dmd-internals@puremagic.com
http://lists.puremagic.com/mailman/listinfo/dmd-internals