comp.lang.ada
 help / color / mirror / Atom feed
From: Duncan Sands <duncan.sands@math.u-psud.fr>
Subject: IEEE arithmetic
Date: Fri, 13 Sep 2002 09:40:52 +0200
Date: 2002-09-13T09:40:52+02:00	[thread overview]
Message-ID: <mailman.1031902862.4685.comp.lang.ada@ada.eu.org> (raw)

I have two problems:

(1) IEEE 754 compliant systems have four rounding modes
for arithmetic operations: round to even (default), round to zero,
round to +infinity, round to -infinity.  How to change the rounding
mode in a fairly portable way?  I am happy if the method is specific
to the GNAT compiler.

Note: the GNU C library has a routine for doing this, but the constants
you feed it to choose the rounding mode seem to have architecture
dependent values (macros are used to give these values common names).
One solution would be to have a way to get hold of the values given by the
macros inside of the Ada program, but I don't know how to do this.

(2) Given a universal real number x (suppose it is in the safe range of some
floating point type T), how to find model numbers a, b of type T such that
a <= x <= b and a and b are adjacent (i.e. [a,b] is a smallest interval
representable in type T and containing x)?  At the moment the best I can do is:

a, b, y : T;

y := T(x);
a := T'Pred (y);
b := T'Succ (y);

Then indeed a <= x <= b but a and b are not adjacent: there is a model
number between them.

Thanks for your help,

Duncan.



             reply	other threads:[~2002-09-13  7:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-13  7:40 Duncan Sands [this message]
2002-09-13 13:03 ` IEEE arithmetic Georg Bauhaus
2002-09-13 13:19   ` Duncan Sands
2002-09-13 15:59 ` Robert A Duff
2002-09-13 16:06   ` Duncan Sands
2002-09-14  0:46     ` Robert A Duff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox