From: invalid@invalid.invalid   
      
   On Thu, 27 Oct 2005 13:03:19 +0200, "Heinrich Wolf"   
    wrote:   
      
   >Hi,   
   >   
   >there are several solutions:   
   >   
   >trunc(2.2) results in 2   
   >round(2.2) results in 2   
   >trunc(2.6) results in 2   
   >round(2.6) results in 3   
   >   
   >trunc() cuts off the fractional part   
   >   
   >round(x) results in the same as trunc(x + 0.5)   
   >   
   >There is a difference between   
   >the mathematical sense of truncating   
   >and the programming laguage implementation   
   >for negative numbers!   
   >trunc(-2.2) results in -2   
   >Maybe you need   
   >if x < 0 then   
   > i := trunc(x) - 1   
   >else   
   > i := trunc(x)   
   >   
   >Then you need to look up the documentation of your compiler's pascal   
   >dialect.   
   >Is it function round(x : real) : real; or   
   >function round(x : real) : integer; ?   
   >It should be function trunc(x : real) : integer;   
   >Maybe you need to assign   
   >i := trunc(round(x));   
   >   
   >There might be several integer types   
   >and several real types   
   >for different range and precision of numbers.   
   >If Integer is -32768 .. 32767,   
   >you cannot assign i := round(40000.2);   
   >There might be integer, longint, word, byte, cardinal, int64, ...   
   >   
   >Regards   
   >Heiner   
   >   
      
   None of these change a real variable to an integer variable. All the   
   above does is produce a rounded off real of VALUE integer, not TYPE   
   integer.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|