# Any way to do asymmetric tolerances in Julia?

**URL:** <https://discourse.julialang.org/t/any-way-to-do-asymmetric-tolerances-in-julia/124933>\
**Category:** General Usage\
**Created:** [January 19, 2025, 10:12pm UTC](https://discourse.julialang.org/t/any-way-to-do-asymmetric-tolerances-in-julia/124933 "2025-01-19T22:12:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [January 19, 2025, 10:12pm UTC](https://discourse.julialang.org/t/any-way-to-do-asymmetric-tolerances-in-julia/124933/1 "2025-01-19T22:12:53Z")

</div>

Hello!

Suppose I have:

```julia
LowerTolerance = 1
UpperTolerance = 3

```

Could I then have an assymmetric tolerance such that if I have a value of `x = 10`, its lower bound would be 9 and upper bound 13?

`Measurements.jl` seems incapable of this, if true, I am looking for another way.

Kind regards

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 19, 2025, 10:44pm UTC](https://discourse.julialang.org/t/any-way-to-do-asymmetric-tolerances-in-julia/124933/2 "2025-01-19T22:44:59Z")

</div>

> [@Ahmed\_Salih](#):
>
> Could I then have an [asymmetric] tolerance such that if I have a value of `x = 10`, its lower bound would be 9 and upper bound 13?

In what context do you want to do this?

If it is for optimization, many packages will allow you to set upper and lower bounds on variables to be whatever you want.

If you want to impose a _constraint_ on a variable during the running of some program, it is better to simply do runtime checks the first time you need this constraint, e.g. in a function add a check like `9 <= x <= 13 || throw(ArgumentError("x = $x is out of bounds"))`. See also [Defining a new type with constraints on values](https://discourse.julialang.org/t/defining-a-new-type-with-constraints-on-values/82782)

> `Measurements.jl` seems incapable of this, if true, I am looking for another way.

Measurements.jl is for propagating _uncertainties_, and it inherently assumes that the uncertainties are normally distributed statistical quantities and that it only needs to track/propagate the mean and stddev.

If you have some other statistical distribution on x, and you are passing it through some calculation and you want to compute the distribution of the output, that’s a much more complicated problem. You may want something like MonteCarloMeasurements.jl in that case.

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [January 19, 2025, 10:49pm UTC](https://discourse.julialang.org/t/any-way-to-do-asymmetric-tolerances-in-julia/124933/3 "2025-01-19T22:49:19Z")

</div>

Hi,

So I want to do it because I just would like to be able to assign values in a DataFrame some lower and upper tolerance bounds, imagine you are doing like a circle and you want to specify its max and min diameter - so not an uncertainity/measurement as such.

Kind regards

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 19, 2025, 11:02pm UTC](https://discourse.julialang.org/t/any-way-to-do-asymmetric-tolerances-in-julia/124933/4 "2025-01-19T23:02:00Z")

</div>

> [@Ahmed\_Salih](#):
>
> assign values in a DataFrame some lower and upper tolerance bounds

Why not just check the values when the `DataFrame` is created? What are you trying to accomplish that a one-time check won’t satisfy?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 19, 2025, 11:28pm UTC](https://discourse.julialang.org/t/any-way-to-do-asymmetric-tolerances-in-julia/124933/5 "2025-01-19T23:28:11Z")

</div>

Check also UncertainData.jl out.
