Summing large Time instance results in ArgumentError: precision (22) too high

Issue #1 resolved
Former user created an issue

When trying to perform an addition of two Time variables:

t2 += t1, where t2 & t1 are 9600 seconds & 9300 seconds respectively, the precision throws an argumentError because the precision is too high.

Is this a bug? Or what should I do in this case? Manually setting the precision to 21 results in tests failing with one-off errors.

Comments (4)

  1. Bruce Santier repo owner

    Thank you for reporting!

    Yes, I would consider this a bug - your inputs are nowhere near the precision limit, so it seems reasonable to assume that a simple addition would not put you over.

    I will cap the limit to the maximum allowed for addition operations like these. This may, unfortunately, surprise some users who are using the maximum precision values and perform an addition, expecting the precision to rise, e.g.:

    final measurement1 = meters(1.23456789012345678901, precision: Precision(21));
    final measurement2 = meters(9.23456789012345678901, precision: Precision(21));
    final result = measurement1 + measurement2;
    expect(result, meters(10.469135780246914)); // fails!
    // the result is actually 10.469135780246912, because the last digits (1's) are lost
    

    Any users who are near the limit would also experience the issue you’ve reported, so correcting this will not break anything that isn’t already broken.

    Version 2.1.1 (available now) prevents the precision cap from being breached through addition operations such as these.

  2. Log in to comment