* Trouble with s'fraction attribute.
@ 2002-09-28 20:01 gilrain
2002-09-28 20:18 ` David C. Hoos, Sr.
0 siblings, 1 reply; 3+ messages in thread
From: gilrain @ 2002-09-28 20:01 UTC (permalink / raw)
Hi all,
I'm writing a program in which I need to seperate the integer and fractional
parts of a float. After reading some documentation, it seemed like this
should do the trick:
with ada.text_io, ada.float_text_io;
use ada.text_io, ada.float_text_io;
procedure test is
number, int, fl : float;
begin
number := 2.9;
int := float'truncation(number);
fl := float'fraction(number);
put(int,0,0,0); new_line;
put(fl,0,0,0);
end test;
When this is run, int truncates as expected outputs as "2.0". Good. However,
fl outputs as "0.7", which isn't at all what I expected (0.9) or wanted.
What's going on here? I expect I've somehow misunderstood what the
s'fraction attribute does; is there a standard function for what I'm trying
to accomplish?
Thanks,
John Thile
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Trouble with s'fraction attribute.
2002-09-28 20:01 Trouble with s'fraction attribute gilrain
@ 2002-09-28 20:18 ` David C. Hoos, Sr.
2002-09-28 21:32 ` gilrain
0 siblings, 1 reply; 3+ messages in thread
From: David C. Hoos, Sr. @ 2002-09-28 20:18 UTC (permalink / raw)
You need to re-read the definition of the 'Fraction attribute.
What you probably want is the 'Remainder attribute, of which
an example is presented here:
with ada.text_io, ada.float_text_io;
use ada.text_io, ada.float_text_io;
procedure remainder is
number, int, fl : float;
begin
number := 3.141592654;
int := float'truncation(number);
fl := float'remainder(Number,int);
put(int); new_line;
put(fl);
end remainder;
----- Original Message -----
From: "gilrain" <john.thile@murraystate.edu>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: September 28, 2002 3:01 PM
Subject: Trouble with s'fraction attribute.
> Hi all,
>
> I'm writing a program in which I need to seperate the integer and fractional
> parts of a float. After reading some documentation, it seemed like this
> should do the trick:
>
> with ada.text_io, ada.float_text_io;
> use ada.text_io, ada.float_text_io;
> procedure test is
> number, int, fl : float;
> begin
> number := 2.9;
>
> int := float'truncation(number);
> fl := float'fraction(number);
>
> put(int,0,0,0); new_line;
> put(fl,0,0,0);
> end test;
>
> When this is run, int truncates as expected outputs as "2.0". Good. However,
> fl outputs as "0.7", which isn't at all what I expected (0.9) or wanted.
> What's going on here? I expect I've somehow misunderstood what the
> s'fraction attribute does; is there a standard function for what I'm trying
> to accomplish?
>
> Thanks,
>
> John Thile
>
>
>
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Trouble with s'fraction attribute.
2002-09-28 20:18 ` David C. Hoos, Sr.
@ 2002-09-28 21:32 ` gilrain
0 siblings, 0 replies; 3+ messages in thread
From: gilrain @ 2002-09-28 21:32 UTC (permalink / raw)
That's what I wanted. Thanks a lot!
John Thile
"David C. Hoos, Sr." wrote:
> You need to re-read the definition of the 'Fraction attribute.
> What you probably want is the 'Remainder attribute, of which
> an example is presented here:
>
> with ada.text_io, ada.float_text_io;
> use ada.text_io, ada.float_text_io;
> procedure remainder is
> number, int, fl : float;
> begin
> number := 3.141592654;
>
> int := float'truncation(number);
> fl := float'remainder(Number,int);
>
> put(int); new_line;
> put(fl);
> end remainder;
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2002-09-28 21:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-28 20:01 Trouble with s'fraction attribute gilrain
2002-09-28 20:18 ` David C. Hoos, Sr.
2002-09-28 21:32 ` gilrain
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox