# High precision interval rounding error

**URL:** <https://discourse.julialang.org/t/high-precision-interval-rounding-error/51885>\
**Category:** General Usage\
**Tags:** bug, intervals\
**Created:** [December 15, 2020, 5:03pm UTC](https://discourse.julialang.org/t/high-precision-interval-rounding-error/51885 "2020-12-15T17:03:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gmouts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gmouts/32/9896_2.png) [@gmouts](https://discourse.julialang.org/u/gmouts)\
**Post date:** [December 15, 2020, 5:03pm UTC](https://discourse.julialang.org/t/high-precision-interval-rounding-error/51885/1 "2020-12-15T17:03:23Z")

</div>

Before everything I need a disclaimer: I do understand that the precision which I set is comically large. However, there is a legitimate reason for what I am doing, but I’m not going to go into it.

The following snippet of code

```julia
using IntervalArithmetic
setprecision(8384);
y = @biginterval sqrt(big(2));
x = @biginterval 1;
exponent(diam(y))
exponent(diam(x))

```

spits out `-8383` and then throws `ERROR: DomainError with 0.0: "x" must be non-zero and finite.`

I assume this is a bug, but I’m not sure where the bug is. It could be in `InvervalArithmetic`, but it could also be as deep as in MPFR. Does anyone have any insight to this?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [December 15, 2020, 5:05pm UTC](https://discourse.julialang.org/t/high-precision-interval-rounding-error/51885/2 "2020-12-15T17:05:48Z")

</div>

The problem is that the logical epsilon for `1` is `0` (Int’s are exact). Did you want `x = @biginterval big(1.0)`?

---

<div class="post-metadata">

**Author:** ![gmouts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gmouts/32/9896_2.png) [@gmouts](https://discourse.julialang.org/u/gmouts)\
**Post date:** [December 15, 2020, 5:21pm UTC](https://discourse.julialang.org/t/high-precision-interval-rounding-error/51885/3 "2020-12-15T17:21:31Z")

</div>

It throws the same error.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [December 15, 2020, 6:46pm UTC](https://discourse.julialang.org/t/high-precision-interval-rounding-error/51885/4 "2020-12-15T18:46:41Z")

</div>

> [@gmouts](#):
>
> ```julia
> using IntervalArithmetic
> setprecision(8384);
> y = @biginterval sqrt(big(2));
> x = @biginterval 1;
> exponent(diam(y))
> exponent(diam(x))
> 
> ```

This has nothing to do with intervals as such.  
`@biginterval 1` contains an interval of 0 width, and then:

```julia

julia> exponent(0.0)
ERROR: DomainError with 0.0:
Cannot be subnormal converted to 0.
Stacktrace:
 [1] (::Base.Math.var"#throw2#4")(::Float64) at ./math.jl:784
 [2] exponent(::Float64) at ./math.jl:789
 [3] top-level scope at REPL[7]:100:

```

It does not make sense to ask for the floating-point exponent of 0.0.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [December 15, 2020, 6:51pm UTC](https://discourse.julialang.org/t/high-precision-interval-rounding-error/51885/5 "2020-12-15T18:51:06Z")

</div>

In principle intervals with that precision should work fine. There may be some issues with displaying the results; if so, please raise them at [https://github.com/JuliaIntervals/IntervalArithmetic.jl/](https://github.com/JuliaIntervals/IntervalArithmetic.jl/) (and preferably help to solve them 😉 )

---

<div class="post-metadata">

**Author:** ![gmouts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gmouts/32/9896_2.png) [@gmouts](https://discourse.julialang.org/u/gmouts)\
**Post date:** [December 15, 2020, 11:34pm UTC](https://discourse.julialang.org/t/high-precision-interval-rounding-error/51885/6 "2020-12-15T23:34:05Z")

</div>

Oh, I see. Since the number 1 can be represented exactly as a floating point number, the upper and lower bounds of the interval are equal. So then the diameter is exactly 0 and its exponent is not defined.

I assumed that since the floating point number 0 is stored in the memory with some exponent, `exponent` would return a number. But, I see why this could be problematic in some cases. Thanks!

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [December 15, 2020, 11:46pm UTC](https://discourse.julialang.org/t/high-precision-interval-rounding-error/51885/7 "2020-12-15T23:46:34Z")

</div>

`0.0` (and `-0.0`) are both kind of special cased in the floating point standards. If you didn’t, they would be interpreted as 1.0\*2^-1024 (except maybe not cause subnormal numbers)
