Skip to content

toSeconds is sometimes inaccurate #20

Open
@liyang

Description

@liyang

Currently implemented as:

toSeconds :: (TimeDiff t, Fractional n) => t -> n
toSeconds = (* recip 1000000) . fromIntegral . view microseconds

rather than

toSeconds = (/ 1000000) . fromIntegral . view microseconds

such that

> toSeconds (microseconds # 5 :: DiffTime) :: Double 
4.9999999999999996e-6

even though a more accurate Double representation exists:

> 5 / 1000000 :: Double
5.0e-6

This can result in an error larger than 0.5us when calling toSeconds with durations of greater than microseconds # (2^32 * 1000000) (assuming 64-bit Double with 52 bits of mantissa), which is a little over 136 years. (Not entirely unreasonable; the first discrepancy is at 11us later.)

Won't fix for now as FDIV is significantly slower than FMUL: check the instruction tables PDF. Comment below if this causes any problems.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions