Hmmm - the odd behaviour with negative numbers is not unique to SBASIC. 
  I've just tried it with QBASIC in NT and it does exactly the same.  
I'd be interested to read the ISO or ANSI standard on this for the 
justification.  Curiously, the 68040 provides two instructions for 
getting an integer from a float:  FINT allows user specified rounding, 
e.g. 'round-to-nearest', while FINTRZ always does 'round-to-zero'.  I 
still can't see the usefulness in having INT(-3.01)=-4 though.  Any 
mathematicians care to comment?

Ian.

> -----Original Message-----
> From: pjwitte 
> Sent: 19 June 2001 16:25
> To: ql-users
> Cc: pjwitte
> Subject: Re: [ql-users] NEXT in FOR-loop
> 
> 
> > >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.
> 
> SMSQ/E, and I think Qdos also, operates with (at least) four
> different rounding schemes:
> 
> 1) PRINT 2.999999            prints 3            (6 decimals)
> This affects the display only, not the maths
> 
> 2) x$ = x: PRINT x$                prints 2.999999, but
> x = 2.9999999: x$ = x: PRINT x$    prints 3! (7 d)
> This rounding takes place during conversion to ascii
> 
>  x = 2.99999: PRINT x        prints the expected 2.99999 (5 d)
> 3) PRINT INT(x)                prints 2
> 4) x% = x: PRINT x%         prints 3
> 
>  x = -2.99999: PRINT x      prints the expected -2.99999
> 3) PRINT INT(x)                prints -3
> 4) x% = x: PRINT x%         prints -3
> 
> Thus INT truncates to next _smaller_ integer, coercion rounds to
> _nearest_ integer. (For integers, method 4 is thus more precise.)
> 
> 
> Per
> 
> 
> 
> 
> 


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