comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: Trouble with s'fraction attribute.
Date: Sat, 28 Sep 2002 15:18:32 -0500
Date: 2002-09-28T15:18:32-05:00	[thread overview]
Message-ID: <mailman.1033244342.29257.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: XEnl9.3281$IO5.1464813@e3500-atl1.usenetserver.com

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





  reply	other threads:[~2002-09-28 20:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-28 20:01 Trouble with s'fraction attribute gilrain
2002-09-28 20:18 ` David C. Hoos, Sr. [this message]
2002-09-28 21:32   ` gilrain
replies disabled

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