goldfirere / units

The home of the units Haskell package
94 stars 19 forks source link

Verify output from the Travel test #11

Closed goldfirere closed 10 years ago

goldfirere commented 10 years ago

At the end of the Travel.hs test, there is a comment with expected output. Currently, on my machine, the output differs somewhat.

Expected output:

46.5 mi
40.0 mi/gal
7.29 lb/gal
8.474625 lb

74.834496 km
14.160249 km/l
0.7273698 kg/l
3.844025 kg

My current output:

46.5 mi
39.999996 mi/gal
7.29 lb/gal
8.474626 lb

74.834496 km
14.160248 km/l
0.7273698 kg/l
3.8440251 kg

Most alarming to me is the second line, with significant rounding error. In examining what's going on, though, this seems somewhat reasonable. The input is 40 mi/gal. Yet, according to the LCSU, this quantity is stored in terms of yards/(cubic yard) -- which is much larger. The precision-saving idea around using Rational doesn't really help here, because we are storing the large number between conversions. So, I think that the observed behavior can be considered correct, but I want a second opinion.

nushio3 commented 10 years ago

Hi, I am aware of this problem so I've deliverately used Float there to magnify the problem. I had forgotten to update the comment, which I did. 9dd5b1a7e6daa95cd

The Rational hack only decreases, not eliminates this kind of problem. I still believe that the rational hack is good, because it should reduce the error-prone floating point multiplication from several times per input-to-exit from twice per input-to-exit. The error will in average increse as square root of the number of float multiplication involved.

It would be interesting to measure this effect in some big computations.

goldfirere commented 10 years ago

Great -- thanks for updating the comments.