cnfsstat rounding trouble

Heath Kehoe hakehoe at avalon.net
Sun May 23 17:15:16 UTC 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On May 23, 2004, at 8:55, Christoph Biedl wrote:

> I've seen that trouble a lot in the last year: The rounding of the
> cnfsstat output fails and always gives zeros, e.g.
>
[...]
>
> How to fix:
> The C-style make-me-double '(1.0 * $free)/(1.0 * $len)' does not help, 
> a
> workaround is to eval the variables before doing the computations:
>
[...]
> This is probably not the best way to solve it.  I'd also be glad to 
> learn
> what really goes wrong.
>
> 	Christoph
>

The variables $free, $len, and $val are BigInts; and perl doesn't
convert their values to floating point automatically for division.

I believe that when you eval() a BigInt, perl converts it to a
regular number value (either an integer or a float) with some loss
of accuracy.  But it's not explicitly documented in the BigInt docs,
so I'm not sure we should rely on it.

Another way is to change those variables into BigFloats (instead of
using eval) like this:
	$free = new Math::BigFloat($free);

(You'll also need to add "use Math::BigFloat;" to the top of the file)

- - heath
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)

iD8DBQFAsNwq4uXPAG0A1J4RAk3GAJ9ysCH5SnU18gEidD6Sx5DU91ClQgCeN7IB
OEMbDlX57SFxUcIquzLXTs8=
=yJDv
-----END PGP SIGNATURE-----



More information about the inn-workers mailing list