Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!uc!cs.umn.edu!rowley From: rowley@cs.umn.edu (Henry A. Rowley) Newsgroups: comp.lang.pascal Subject: Re: TP 5.5 int() function Keywords: TP,Turbo,Pascal Message-ID: <1990Aug15.181830.5385@cs.umn.edu> Date: 15 Aug 90 18:18:30 GMT References: <1990Aug15.160719.12762@ux1.cso.uiuc.edu> Distribution: comp Organization: University of Minnesota, Minneapolis - CSCI Dept. Lines: 27 In article <1990Aug15.160719.12762@ux1.cso.uiuc.edu> aindiana@osiris.cso.uiuc.edu (Daiv Stoner) writes: > rate:=2.01; > reg:=12.5; > value:=rate*reg*100+0.5; > x := int(value)/100; >writeln('rate=',rate:8:4,' reg=',reg:8:4,' total=',rate*reg:8:4,' x=',x:8:4); >I get this output: > >rate= 2.0100 reg= 12.5000 total= 25.1250 x= 25.1200 It is probably a round off error. You could verify the following statements by printing the entire number, not a rounded version of it: ie writeln(rate), not writeln(rate:8:4). Anyway, here is where the round off is occurring: Lets say the actual value of rate is 25.124999999999999. Then, if you multiply by 100, you get 2512.49999999999. Adding 0.5 gives 2512.999999999. Then, truncate to the integer part of the number, and you get 2512. Dividing by one hundred gives you the final answer 25.12. As you can see, this is due to rounding errors, not a bug. Henry A. Rowley Internet: rowley@cs.umn.edu -or- rowley@ux.acs.umn.edu THE CONTENT OF THE PROPOSITIONS - _The Shockwave Rider_ by John Brunner-------- #1: That this is a rich planet. Therefore poverty and hunger are unworthy of it, and since we can abolish them, we must. #2: That we are a civilized species. Therefore none shall henceforth gain illict advantage by reason of the fact that we together know more that one of us can know.