On Tuesday, 29 September 2015 at 21:04:06 UTC, Wulfrick wrote:
Is there an interval arithmetic library in D? I couldn’t find one.
None I am aware of.

In case I had to write my own, I understand that the IEEE standard floating point arithmetic provides operations for rounding up or down certain operations like summing, subtracting, etc. (thus overriding the default behavior of rounding to nearest representable).

How do I access this functionality in D? At first I thought that std.math.nextDown and nextUp is what I needed, but not so. Apparently these functions return the previous or next representable *after* the calculation has been done.

For example, I would like the value of x+y rounded in the arithmetic towards -\infty, which may or may not be nextDown(x+y).

Any luck?
Thanks for reading!

fencv.h [1] + a few extern(C) declarations could work - changes the rounding mode.
Maybe there is an inline ASM solution, too.

I have never tried to use that from D. The FENV_ACCESS pragma could cause problems - don't know how to pass that info to a D compiler (never tried to figure it out).

It may be easier to generate an binding for an existing C/C++ lib, e.g. [2] (page is in German, but the downloadable tar.gz ("komprimierte (gzipped) tar-Datei") contains an English readme. Boost also contains an interval arithmetic lib [3], but the use of C++ templates will most likely force you to write some glue code in C++...


[1] http://www.cplusplus.com/reference/cfenv/
[2] http://www.ti3.tuhh.de/keil/profil/ (GPL)
[3] http://www.boost.org/doc/libs/1_58_0/libs/numeric/interval/doc/interval.htm

Reply via email to