comp.lang.ada
 help / color / mirror / Atom feed
From: Keith Thompson <kst-u@mib.org>
Subject: Re: Convert Unsigned_32 to Ieee_Float_32
Date: Thu, 26 Oct 2006 22:03:05 GMT
Date: 2006-10-26T22:03:05+00:00	[thread overview]
Message-ID: <ln4ptq3fc7.fsf@nuthaus.mib.org> (raw)
In-Reply-To: 1161883988.538024.321940@b28g2000cwb.googlegroups.com

"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.



      parent reply	other threads:[~2006-10-26 22:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox