trunc() and frac() in pascal ?

General discussion on mikroPascal.
Post Reply
Author
Message
sharpals
Posts: 10
Joined: 17 May 2009 09:29

trunc() and frac() in pascal ?

#1 Post by sharpals » 17 May 2009 09:33

hello, i want programm the silab I570 and need

the frac() and trunc() as in delphi to split a real into the integer and rest-part.

Doe any how does it goes in micropascal ?

greatings michael

sharpals
Posts: 10
Joined: 17 May 2009 09:29

hello i think this should be go ?

#2 Post by sharpals » 17 May 2009 09:51

i tested this

RFREQ:=123.456;
RFREQ_int :=integer(RFREQ); // integerpart
RFREQ_frac:=integer((RFREQ-RFREQ_int)); / rest

is this right ?

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: trunc() and frac() in pascal ?

#3 Post by Dany » 17 May 2009 11:45

sharpals wrote:hello, i want programm the silab I570 and need
the frac() and trunc() as in delphi to split a real into the integer and rest-part.
Doe any how does it goes in micropascal ?
Hi, Trunc and frac do not exist (yet) in mikroPascal, see http://www.mikroe.com/forum/viewtopic.php?t=19177.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: hello i think this should be go ?

#4 Post by janni » 17 May 2009 14:25

sharpals wrote: RFREQ:=123.456;
RFREQ_int :=integer(RFREQ); // integerpart
RFREQ_frac:=integer((RFREQ-RFREQ_int)); / rest

is this right ?
Yes, its right. The floating-point math in mP does no rounding, so typecasting to integer is equivalent to truncation. You may also use the modf function to get both the integer and fractional parts.

Post Reply

Return to “mikroPascal General”