jhgrizz has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, It's Friday, can't think anymore, help...Do you see anything wrong with the following? I don't see how the results are -2 and 0s
$ostype = $inforec->ostype; $directory = $inforec->directory; $size = int($inforec->size); $timeframe = $inforec->timeframe; print "build_mm_rec: $ostype, $directory, $size, $timeframe\n"; if ($ostype eq 'N') { print "getting space, size: $size\n"; $TotalNumberOfFreeBytes = (Win32::DriveInfo::DriveSpace($directo +ry))[6]; $TotalNumberOfFreeBytes = int($TotalNumberOfFreeBytes); print "space 1: $TotalNumberOfFreeBytes\n"; my $holder = $TotalNumberOfFreeBytes - 1; print "space 1.5: $holder\n"; $holder = $size / $size; print "space 1.6: $holder\n"; $TotalNumberOfFreeBytes = $TotalNumberOfFreeBytes / $size; print "space 2: $TotalNumberOfFreeBytes\n"; $TotalNumberOfFreeBytes = $TotalNumberOfFreeBytes / $size; print "space 3: $TotalNumberOfFreeBytes\n"; $TotalNumberOfFreeBytes = (((Win32::DriveInfo::DriveSpace($direc +tory))[6])/$size)/$size; } else { $TotalNumberOfFreeBytes = getFreeDisk($size); print "unix space\n"; } print "space: $TotalNumberOfFreeBytes\n";
result build_mm_rec: N, c:, 1024, mm
getting space, size: 1024
space 1: 17298208768
space 1.5: -2
space 1.6: 1
space 2: 0
space 3: 0
space: 0

Replies are listed 'Best First'.
Is 17298208768 "too big"?
by cebrown (Pilgrim) on Aug 23, 2002 at 23:06 UTC
    It looks like you are using Windows, and I'm guessing ActiveState, which I believe was compiled 32-bit, so your maximum integer is 2**32, which is less than the value in $TotalNumberOfFreeBytes

    You probably need to use Math::BigInt or pursue another design path.

      ...I think the first time you're referring to $TotalNumberOfFreeBytes, Perl is treating it as a string, so it'll print the way you want; it's once you start doing math on it that things get funky.
      Yes, it's too big. I want to convert it to mb. I did not have this problem before I added my code to someone else's programs. I would like to limit it down to 5 digits.
      Thanks for your help. Math:BigInt took care of the problem. Thanks to you all
Re: wrong record type?
by BrowserUk (Patriarch) on Aug 24, 2002 at 07:46 UTC

    I am completely confused by this post and the follow-ups. The attached prog and output was run on AS Perl 5.6.1 under Win32 and as you can see, it has no problems handling integer values > 32-bit. When they get bigger than 2**49 you need to use printf to output them as integer values and they start loosing precision somewhere after 2**56.

    As 2**56 is 72,057,594,037,927,936 or 72 Peta-bytes represents something like 12MB for every human being on the planet. It is unlikely that any single directory or drive is going to have more than that much free space available.

    Quite why you were seeing your problem or why Math::BigInt cured it eludes me.

    Is there something special about the numbers returned from Win32::DriveInfo::Drivespace()? I tried it on my system but my drives aren't big enough to push the value over the 32-bit limit.

    #! perl -w my $bignum = 17298208768; print $bignum, $/; print $bignum / 1024, $/; print int($bignum), $/; print int($bignum/1024), $/; print $_, ' : ', 2**$_,$/ for (32..64); printf "%d : %20.0f\n", $_, 2**$_ for (50..57); __END__ # Output C:\test>192471 17298208768 16892782 17298208768 16892782 32 : 4294967296 33 : 8589934592 34 : 17179869184 35 : 34359738368 36 : 68719476736 37 : 137438953472 38 : 274877906944 39 : 549755813888 40 : 1099511627776 41 : 2199023255552 42 : 4398046511104 43 : 8796093022208 44 : 17592186044416 45 : 35184372088832 46 : 70368744177664 47 : 140737488355328 48 : 281474976710656 49 : 562949953421312 50 : 1.12589990684262e+015 51 : 2.25179981368525e+015 52 : 4.5035996273705e+015 53 : 9.00719925474099e+015 54 : 1.8014398509482e+016 55 : 3.6028797018964e+016 56 : 7.20575940379279e+016 57 : 1.44115188075856e+017 58 : 2.88230376151712e+017 59 : 5.76460752303423e+017 60 : 1.15292150460685e+018 61 : 2.30584300921369e+018 62 : 4.61168601842739e+018 63 : 9.22337203685478e+018 64 : 1.84467440737096e+019 50 : 1125899906842624 51 : 2251799813685248 52 : 4503599627370496 53 : 9007199254740992 54 : 18014398509481984 55 : 36028797018963968 56 : 72057594037927936 57 : 144115188075855870 C:\test>

    What's this about a "crooked mitre"? I'm good at woodwork!