* Re: Convert Unsigned_32 to Ieee_Float_32
2006-10-26 17:33 Convert Unsigned_32 to Ieee_Float_32 Richard Charts
2006-10-26 21:19 ` Ian Caldwell
@ 2006-10-26 22:03 ` Keith Thompson
1 sibling, 0 replies; 3+ messages in thread
From: Keith Thompson @ 2006-10-26 22:03 UTC (permalink / raw)
"Richard Charts" <richard.charts@gmail.com> writes:
> Well I ran into a fun error today.
>
> Apparently on Green Hills,
> Interfaces.Unsigned_32( [Some Item of Type Interfaces.Ieee_Float_32])
> causes a compiler error.
> C:\DOCUME~1\...\LOCALS~1\Temp\gh_lk1.s 2212: lwz f29,112(sp)
> C:\DOCUME~1\...\LOCALS~1\Temp\gh_lk1.s 2212: ----^-
> C:\DOCUME~1\...\LOCALS~1\Temp\gh_lk1.s 2212: expected register
>
> So just to get my project compiling, I substituted:
> Interfaces.Unsigned_32'Value(Interfaces.Ieee_Float_32'Image(Real_Obj.Resolution))
>
> But that's a rather expensive convertion.
> Can anyone recommend a better way until, I find a way around the above
> error?
That's not going to work anyway (though, as you say, it will compile).
The string returned by Ieee_Float_32'Image isn't going to be a valid
integer literal, so Unsigned_32'Value will raise Constraint_Error.
The first thing I'd try is to do the conversion via some other
intermediate type; maybe the bug doesn't happen to affect Float_64,
for example. If that fails, you could write your own brute-force
conversion function. If you just want to get it working quickly,
without worrying about efficiency, you could instantiate Float_IO for
tpe IEEE_Float_32, then use Put with Fore => 0, Aft => 0, Exp => 0 to
write it to a string, delete or otherwise ignore the trailing ".0" (or
".1", or whatever), and apply Unsigned_32'Value to that.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
^ permalink raw reply [flat|nested] 3+ messages in thread