Only guessing because I can't try this until I get home, but when n 
reaches the value 2.9999....  (the nearest it'll get to 3.00 because 
0.01 is not represented exactly internally [that would need an infinite 
number of bits]), then PRINT n  will round up to 3, whereas INT(n) will 
return the correct answer (2) which needs no rounding and therefore 
prints as 2.

Try this:
FOR n=2.953125 TO 3.03125 STEP 0.015625:PRINT n, INT(n)
and see if you get any unexpected results.

Ian.


> -----Original Message-----
> From: CMOUR 
> Sent: 18 June 2001 10:34
> To: ql-users
> Cc: CMOUR
> Subject: RE: [ql-users] NEXT in FOR-loop
> 
> 
> Yes,but what I dont understand is how the "n" value in my 
> example can be OK
> when the INT(n) does not ?!
> 
> -----Message d'origine-----
> De : Malcolm Lear [mailto:[EMAIL PROTECTED]]
> Envoy� : lundi 18 juin 2001 11:30
> � : [EMAIL PROTECTED]
> Objet : Re: [ql-users] NEXT in FOR-loop
> 
> 
> Yes rather annoying. I've come across this problem several times. I 
> quite often
> add a small value to n solve it. i.e.  INT(n+0.00001). I 
> assume its got 
> something
> to do with internal rounding.
> 
> 
> 
> Claude Mourier 00 wrote:
> 
> > As I see a question about FOR/NEXT loops, I have mine:
> > the subsequent peice of code gives me an unexpected result 
> > FOR n = 2.95 to 3.05 STEP 0.01 : print n, INT(n)
> > Why ?
> > 
> > Claude
> > (I am using QPC2v2.00 and SMSQ/e v2.98)
> > 
> > 
> 


Visit our website at http://www.ubswarburg.com

This message contains confidential information and is intended only 
for the individual named.  If you are not the named addressee you 
should not disseminate, distribute or copy this e-mail.  Please 
notify the sender immediately by e-mail if you have received this 
e-mail by mistake and delete this e-mail from your system.

E-mail transmission cannot be guaranteed to be secure or error-free 
as information could be intercepted, corrupted, lost, destroyed, 
arrive late or incomplete, or contain viruses.  The sender therefore 
does not accept liability for any errors or omissions in the contents 
of this message which arise as a result of e-mail transmission.  If 
verification is required please request a hard-copy version.  This 
message is provided for informational purposes and should not be 
construed as a solicitation or offer to buy or sell any securities or 
related financial instruments.

Reply via email to