comp.lang.ada
 help / color / mirror / Atom feed
* trunc
@ 1999-03-18  0:00 phadreus
  1999-03-18  0:00 ` trunc Matthew Heaney
  1999-03-19  0:00 ` trunc Michael F Brenner
  0 siblings, 2 replies; 8+ messages in thread
From: phadreus @ 1999-03-18  0:00 UTC (permalink / raw)




what's the most efficient way within Ada
to obtain the whole-number portion Y of
a floating-point number X?

for example,

X = 5.5  Y = 5.0

X = 2.9  Y = 2.0

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: trunc
  1999-03-18  0:00 trunc phadreus
@ 1999-03-18  0:00 ` Matthew Heaney
  1999-03-18  0:00   ` trunc Nick Roberts
  1999-03-18  0:00   ` trunc Tucker Taft
  1999-03-19  0:00 ` trunc Michael F Brenner
  1 sibling, 2 replies; 8+ messages in thread
From: Matthew Heaney @ 1999-03-18  0:00 UTC (permalink / raw)


phadreus@my-dejanews.com writes:

> what's the most efficient way within Ada
> to obtain the whole-number portion Y of
> a floating-point number X?
> 
> for example,
> 
> X = 5.5  Y = 5.0
> 
> X = 2.9  Y = 2.0

T'Floor





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

* Re: trunc
  1999-03-18  0:00 ` trunc Matthew Heaney
  1999-03-18  0:00   ` trunc Nick Roberts
@ 1999-03-18  0:00   ` Tucker Taft
  1999-03-19  0:00     ` trunc Michael Stark
  1 sibling, 1 reply; 8+ messages in thread
From: Tucker Taft @ 1999-03-18  0:00 UTC (permalink / raw)


Matthew Heaney wrote:
> 
> phadreus@my-dejanews.com writes:
> 
> > what's the most efficient way within Ada
> > to obtain the whole-number portion Y of
> > a floating-point number X?
> >
> > for example,
> >
> > X = 5.5  Y = 5.0
> >
> > X = 2.9  Y = 2.0
> 
> T'Floor

I suspect that T'Truncation is more what they had in mind.
T'Truncation(-3.5) = -3.0, whereas T'Floor(-3.5) = 4.0

-- 
-Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA




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

* Re: trunc
  1999-03-18  0:00 ` trunc Matthew Heaney
@ 1999-03-18  0:00   ` Nick Roberts
  1999-03-18  0:00   ` trunc Tucker Taft
  1 sibling, 0 replies; 8+ messages in thread
From: Nick Roberts @ 1999-03-18  0:00 UTC (permalink / raw)


I suspect the 'Truncation' attribute is more likely to be what Phadreus is
looking for (see RM95 A.5.3), since it 'chops off' the fractional part,
whether the number is positive or negative.  As for efficiency, I would
guess that the use of the attribute is likely to be the most efficient
implementation for the vast majority of (native code) compilers.

-------------------------------------
Nick Roberts
-------------------------------------








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

* Re: trunc
  1999-03-18  0:00 trunc phadreus
  1999-03-18  0:00 ` trunc Matthew Heaney
@ 1999-03-19  0:00 ` Michael F Brenner
  1999-03-19  0:00   ` trunc Markus Kuhn
  1999-03-22  0:00   ` trunc Howard W. LUDWIG
  1 sibling, 2 replies; 8+ messages in thread
From: Michael F Brenner @ 1999-03-19  0:00 UTC (permalink / raw)



The most efficient way is to go to URL http://www.adahome.com/rm95/
which is the Ada 95 Reference Manual which points you to the URL:

    http://www.adahome.com/rm95/rm9x-A-05-03.html

which defines the floor attribute which works like this:

   y:=x'floor;      -- Postcondition: Y is now the whole-number of X
   f:=x'fraction;   -- Postcondition: F is now the fractional value of X



> what's the most efficient way within Ada
> to obtain the whole-number portion Y of
> a floating-point number X?
 




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

* Re: trunc
  1999-03-19  0:00 ` trunc Michael F Brenner
@ 1999-03-19  0:00   ` Markus Kuhn
  1999-03-22  0:00   ` trunc Howard W. LUDWIG
  1 sibling, 0 replies; 8+ messages in thread
From: Markus Kuhn @ 1999-03-19  0:00 UTC (permalink / raw)


mfb@mbunix.mitre.org (Michael F Brenner) writes:
|>    y:=x'floor;      -- Postcondition: Y is now the whole-number of X

GNAT 3.11p says "prefix of 'floor' attribute must be a type"
and the ARM agrees.

Correct would have been:

  y := float'floor(x);

Floor is a function, therefore it should look like one. Your
syntax looks like what might have been a convenient abbreviation,
but Ada is not about abbreviations.

Markus

-- 
Markus G. Kuhn, Computer Laboratory, University of Cambridge, UK
Email: mkuhn at acm.org,  WWW: <http://www.cl.cam.ac.uk/~mgk25/>




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

* Re: trunc
  1999-03-18  0:00   ` trunc Tucker Taft
@ 1999-03-19  0:00     ` Michael Stark
  0 siblings, 0 replies; 8+ messages in thread
From: Michael Stark @ 1999-03-19  0:00 UTC (permalink / raw)


Tucker Taft wrote:
> 
> Matthew Heaney wrote:
> >
> > phadreus@my-dejanews.com writes:
> >
> > > what's the most efficient way within Ada
> > > to obtain the whole-number portion Y of
> > > a floating-point number X?
> > >
> > > for example,
> > >
> > > X = 5.5  Y = 5.0
> > >
> > > X = 2.9  Y = 2.0
> >
> > T'Floor
> 
> I suspect that T'Truncation is more what they had in mind.
> T'Truncation(-3.5) = -3.0, whereas T'Floor(-3.5) = 4.0

Tuck --

I assume you mean T'floor(-3.5) = -4.0 

I wouldn't want to confuse anyone more than they are already ;)

Mike

> 
> --
> -Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
> Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
> AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA

-- 
Michael Stark
Goddard Research & Study Fellow
University of Maryland, College Park
e-mail: mstark@cs.umd.edu
phone: (301) 405-2721
"Where have you gone Joe DiMaggio, a nation turns its lonely eyes to
you"
    -- Simon & Garfunkel




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

* Re: trunc
  1999-03-19  0:00 ` trunc Michael F Brenner
  1999-03-19  0:00   ` trunc Markus Kuhn
@ 1999-03-22  0:00   ` Howard W. LUDWIG
  1 sibling, 0 replies; 8+ messages in thread
From: Howard W. LUDWIG @ 1999-03-22  0:00 UTC (permalink / raw)
  To: Michael F Brenner

Besides the issue, as Markus K. pointed out, that these attributes
are functions, the description below of the 'Fraction attribute is
likely misleading.

The inference I draw from the description below is that if I have
a floating-point number X of type T, then I can decompose X into
an integer part and a fractional part, whose sum is X, using these
two attributes.  However, using the URL given below, one can see
that 'Fraction is the counterpart of 'Exponent to decompose a
floating-point number into a fractional mantissa and an exponent, such that
     X := T'Fraction(X) * T'Machine_Radix**T'Exponent(X).

HWL

Michael F Brenner wrote:

> The most efficient way is to go to URL http://www.adahome.com/rm95/
> which is the Ada 95 Reference Manual which points you to the URL:
>
>     http://www.adahome.com/rm95/rm9x-A-05-03.html
>
> which defines the floor attribute which works like this:
>
>    y:=x'floor;      -- Postcondition: Y is now the whole-number of X
>    f:=x'fraction;   -- Postcondition: F is now the fractional value of X
>
> > what's the most efficient way within Ada
> > to obtain the whole-number portion Y of
> > a floating-point number X?







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

end of thread, other threads:[~1999-03-22  0:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-03-18  0:00 trunc phadreus
1999-03-18  0:00 ` trunc Matthew Heaney
1999-03-18  0:00   ` trunc Nick Roberts
1999-03-18  0:00   ` trunc Tucker Taft
1999-03-19  0:00     ` trunc Michael Stark
1999-03-19  0:00 ` trunc Michael F Brenner
1999-03-19  0:00   ` trunc Markus Kuhn
1999-03-22  0:00   ` trunc Howard W. LUDWIG

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