javascriptinterval-arithmetic

Conservative interval arithmetic library in Javascript


Is there a good existing library for conservative interval arithmetic in Javascript?

By conservative I mean that given two intervals representing ranges of real numbers (whose endpoints happen to be floating point), their interval sum contains all sums of real numbers from the original intervals, and similarly for the other operations. The only library found by a quick search is https://github.com/Jeff-Tian/JavaScriptIntervalArithmetic, but it doesn't appear to be conservative.

Since we don't have access to rounding modes, it's fine (actually preferable for speed) if the intervals aren't optimal. For example, it would be fine if the square of a number was conservatively approximated by [(1-epsilon)*(x*x),(1+epsilon)*(x*x)], even though this is larger than the optimal floating point interval.


Solution

  • Have a look at https://github.com/maurizzzio/interval-arithmetic whose intervals represent floating point numbers bounding it with the next/previous double-precision floating point number that can be represented

    var Interval = require('interval-arithmetic');
    
    // { lo: 0.3333333333333333, hi: 0.3333333333333333 }
    new Interval().singleton(1 / 3); 
    
    // { lo: 0.33333333333333326, hi: 0.33333333333333337 }
    new Interval().boundedSingleton(1 / 3);
    

    Typed Arrays now provide a way to deal with the bytes that make a double-precision floating number, the library modifies the last bit of the significand of this representation here and all operations carry over this rounding error