digitalmars.D - Converting from C
- =?ISO-8859-1?Q?Julio_C=E9sar_Carrascal_Urquijo?= (20/20) Jun 04 2004 How do I convert this C declaration to D:
- Kevin Bealer (31/42) Jun 04 2004 Maybe like this:
How do I convert this C declaration to D: union FloatIEEE754 { float floatValue; struct { unsigned int mantissa : 23; unsigned int exponent : 8; unsigned int sign : 1; } mpn; }; -- Julio César Carrascal Urquijo http://jcesar.f2o.org/ -----BEGIN GEEK CODE BLOCK----- Version: 3.12 GCS$ d- s+:+ a-- C++> ULS++ P++ L+> !E W+++ N+ o? K? w++> O--- M V? PS+ PE Y+ PGP t+ 5- X+++ R- tv+(++) b++> DI! D++> G e+> h-- r- y+ ------END GEEK CODE BLOCK------
Jun 04 2004
In article <c9q9ns$14mm$1 digitaldaemon.com>, =?ISO-8859-1?Q?Julio_C=E9sar_Carrascal_Urquijo?= says...How do I convert this C declaration to D: union FloatIEEE754 { float floatValue; struct { unsigned int mantissa : 23; unsigned int exponent : 8; unsigned int sign : 1; } mpn; };Maybe like this: struct FloatIEEE754 { float floatValue; int as_uint() { return * cast(uint*) (& floatValue); } uint sign() { return as_uint >>> 31; } uint exponent() { return as_uint << 1 >> 24; } uint mantissa() { return as_uint << 9 >>> 9; } } This will allow: struct FloatIEEE754 x; x.floatValue = 1.123; int a = x.sign; int b = x.exponent; int c = x.mantissa; I don't remember how C++ bitfields or IEEE floats are packed, so you may need to reverse the shifts. Kevin
Jun 04 2004