Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: bigint - float?

by sifukurt (Hermit)
on Nov 23, 2001 at 20:19 UTC ( [id://127134]=note: print w/replies, xml ) Need Help??


in reply to bigint - float?

If I understand your problem, then this works with the newest version of Math::BigInt. I'm fairly certain that it won't work with some earlier versions. I seem to remember having trouble with this sort of thing in the past.
$x = Math::BigInt->bstr( $bigint ); $bits = int( log( $x ) / log( 2 ) ) + 1;
___________________
Kurt

Replies are listed 'Best First'.
length * 3.3219
by jhanna (Scribe) on Nov 23, 2001 at 21:38 UTC
    I'm using whatever BigInt came with ActivePerl... It's likely not the latest. It does occur to me that I can probably do something like:

    $bits=int((length($bigint)-1) * 3.3219)+1;

    where 3.3219 is log(10)/log(2) and the length of $bigint is relatively large assuming that length($bigint) returns the length of the string / ie number of decimals.

    It also occurred to me that I could do a manual conversion to float by something like this:

    $float=substr($bigint,1,1).'.'.substr($bigint,2).'e'.(length($bigint)-2);

    where the point is to create a float string value out of the bigint string value...

    Either of these might work, but they're a bit ugly...

    j

      As long as you have a fairly recent ActivePerl, you should be ok. I think only relatively old versions of Math::BigInt did weird things sometimes with bstr(). The newest version of Math::BigInt installs like a charm on a Win32 system, btw. So either way, you might be better off installing the newest version.
      ___________________
      Kurt

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://127134]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2024-04-19 18:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found