home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.pascal.borland      Borland Pascal was actually pretty neat      2,978 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 1,935 of 2,978   
   Heinrich Wolf to All   
   Re: change type   
   27 Oct 05 13:03:19   
   
   From: invalid@invalid.invalid   
      
   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   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca