comp.lang.ada
 help / color / mirror / Atom feed
* IEEE arithmetic
@ 2002-09-13  7:40 Duncan Sands
  2002-09-13 13:03 ` Georg Bauhaus
  2002-09-13 15:59 ` Robert A Duff
  0 siblings, 2 replies; 6+ messages in thread
From: Duncan Sands @ 2002-09-13  7:40 UTC (permalink / 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.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: IEEE arithmetic
  2002-09-13  7:40 IEEE arithmetic Duncan Sands
@ 2002-09-13 13:03 ` Georg Bauhaus
  2002-09-13 13:19   ` Duncan Sands
  2002-09-13 15:59 ` Robert A Duff
  1 sibling, 1 reply; 6+ messages in thread
From: Georg Bauhaus @ 2002-09-13 13:03 UTC (permalink / raw)


Duncan Sands <duncan.sands@math.u-psud.fr> wrote:
: 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.

I'm not sure whether this might be what you are looking for, but
one of Robert Dewar's students, Sam Figueroa, has written a thesis
about Ada and floating point that might have some relevant information.
(If you don't have this already, and I'm not completely missing the
point :)
http://www.cs.nyu.edu/csweb/Research/Theses/figueroa_sam.ps.gz

--  Georg



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: IEEE arithmetic
  2002-09-13 13:03 ` Georg Bauhaus
@ 2002-09-13 13:19   ` Duncan Sands
  0 siblings, 0 replies; 6+ messages in thread
From: Duncan Sands @ 2002-09-13 13:19 UTC (permalink / raw)


On Friday 13 September 2002 15:03, Georg Bauhaus wrote:
> Duncan Sands <duncan.sands@math.u-psud.fr> wrote:
> : 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.
>
> I'm not sure whether this might be what you are looking for, but
> one of Robert Dewar's students, Sam Figueroa, has written a thesis
> about Ada and floating point that might have some relevant information.
> (If you don't have this already, and I'm not completely missing the
> point :)
> http://www.cs.nyu.edu/csweb/Research/Theses/figueroa_sam.ps.gz

Thanks Georg, it looks like an excellent way to get started.

All the best,

Duncan.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: IEEE arithmetic
  2002-09-13  7:40 IEEE arithmetic Duncan Sands
  2002-09-13 13:03 ` Georg Bauhaus
@ 2002-09-13 15:59 ` Robert A Duff
  2002-09-13 16:06   ` Duncan Sands
  1 sibling, 1 reply; 6+ messages in thread
From: Robert A Duff @ 2002-09-13 15:59 UTC (permalink / raw)


Duncan Sands <duncan.sands@math.u-psud.fr> writes:

> 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.

If you use the version SofCheck's AdaMagic that generates C,
you can call C macros from Ada using pragma Import.
Most compilers don't allow that, however.

Another way to call a macro is to write a C function that calls the
macro.  Then use pragma Import to call the C function from Ada.  That's
kind of annoying if the reason it's a macro is to get inline code.  But
that's probably not your case -- you probably don't want to set the mode
repeatedly in a tight loop.

- Bob



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: IEEE arithmetic
  2002-09-13 15:59 ` Robert A Duff
@ 2002-09-13 16:06   ` Duncan Sands
  2002-09-14  0:46     ` Robert A Duff
  0 siblings, 1 reply; 6+ messages in thread
From: Duncan Sands @ 2002-09-13 16:06 UTC (permalink / raw)


> If you use the version SofCheck's AdaMagic that generates C,
> you can call C macros from Ada using pragma Import.
> Most compilers don't allow that, however.
>
> Another way to call a macro is to write a C function that calls the
> macro.  Then use pragma Import to call the C function from Ada.  That's
> kind of annoying if the reason it's a macro is to get inline code.  But
> that's probably not your case -- you probably don't want to set the mode
> repeatedly in a tight loop.

I did consider (and still am considering) writing such a C function.
My only objection to it is... that it is ugly!

Thanks for helping,

Duncan.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: IEEE arithmetic
  2002-09-13 16:06   ` Duncan Sands
@ 2002-09-14  0:46     ` Robert A Duff
  0 siblings, 0 replies; 6+ messages in thread
From: Robert A Duff @ 2002-09-14  0:46 UTC (permalink / raw)


Duncan Sands <duncan.sands@math.u-psud.fr> writes:

> I did consider (and still am considering) writing such a C function.
> My only objection to it is... that it is ugly!

Interfacing between two languages is ugly by its very nature.

- Bob



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2002-09-14  0:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-13  7:40 IEEE arithmetic Duncan Sands
2002-09-13 13:03 ` 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

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