Re: Converting integer + mantissa to float

[email protected] (Rob Dixon)
Newsgroups perl.beginners
Message-ID <[email protected]>
Jay Savage wrote:
>
> I'm having trouble wrapping my brain around this:
> 
> I am writing a script that will receive two integers as input that
> represent a single float. The first is the integer part, the second is
> hat mantissa. How do I recomine them into a single float? all I'm
> coming up with so far is:
> 
> my $float = $int_part . '.' . $matissa; #or
> my $float = sprintf "%u.%u", $int_part, $mantissa;
> 
> It seems, though, like there should be a more elegant way to handle
> this than turning two numbers into a string to turn around and use the
> result as  number again. What am I missing?

Hi Jay

I don't think you're missing anything. I would write

  my $float = "$int_part.$mantissa";

which is the same as your first solution, but a little more concise.

I think this is very elegant indeed; please tell me about your misgivings?

Rob
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.