> ... But this is quite annoying :

Yes :-), but whenever you use irrational numbers (cannot be represented 
exactly in a limited precision number system) you will encounter this 
problem and any solution will have to be a compromise.  Personally I 
prefer the rounding because that way there is some spare precision to 
delay accumulated errors showing up in printed results.  I'll try and 
find the time to do some experiments this evening.  I really ought to 
get on with some work now though!

Ian.

> -----Original Message-----
> From: CMOUR 
> Sent: 18 June 2001 14:45
> To: ql-users
> Cc: CMOUR
> Subject: RE: [ql-users] NEXT in FOR-loop
> 
> 
> Thank's a lot for all the answers. But this is quite annoying 
> : especially
> because behavior is not the same for PRINT and INT. Better if 
> PRINT returns
> something like 2.99999 (in fact SMS loves exponential form I personaly
> hate). I'm not sure but I think even FDEC$(n, 9, 8) returns 3.00000.
> 
> Claude
> 
> -----Message d'origine-----
> De : ZN [mailto:[EMAIL PROTECTED]]
> Envoy� : lundi 18 juin 2001 15:36
> � : [EMAIL PROTECTED]
> Objet : Re: [ql-users] NEXT in FOR-loop
> 
> 
> >> 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 ?
> 
> >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.
> 
> Print returns 3 because of rounding of the QL float precision 
> of >9 digits
> to 7 digits available for printing. INT operates directly 
> from QL float
> format and will therefore give the right result: 2. This will again be
> rounded to 7 digitsby print but obviously 2.0000000 = 
> 2.000000 so nothing
> will change.
> 
> Nasta
> 
> 


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