Re: Converting integer + mantissa to float

[email protected] ("Dr.Ruud")
Newsgroups perl.beginners
Organization Chaos rules.
Message-ID <[email protected]>
"Jay Savage" schreef:

> 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?
>
> my $float = $int_part . '.' . $matissa; #or
> my $float = sprintf "%u.%u", $int_part, $mantissa;

The sprintf() makes me think that you receive the numbers, or at least
the mantissa, with possible leading zeroes.

I would add the venus operator:

my $float = 0+ sprintf("%u.%u", $int_part, $mantissa);

The $int_part is always non-negative?

-- 
Affijn, Ruud

"Gewoon is een tijger."
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.