Skip navigation.
 
mlRe: NSTimer or double to int cast (Bug?)
FROM : Chris Kane
DATE : Fri Jan 10 21:03:19 2003

On Friday, January 10, 2003, at 07:49 AM, Chris Ridd wrote:
> You're passing a double to NSLog but only using the %f (float) format
> specifier. That doesn't address the fact that value does seem to be
> less
> than 1, but it might be worth seeing if using %lf made a difference.


%f is for doubles, as is %e and %g.  All floats are promoted to doubles
in C/ObjC when they occur in the varargs region of a function call with
varargs (as with printf()).


Marco - have you tried using something other than NSLog() to do the
print-out?  Also, try assigning the cast value to a local, then using
the local as an argument to print out, as in:

   int casted = (int)[timer timeInterval];  // could also try
(int)([timer timeInterval] + 0.001)
          NSLog(......, casted);

and see if that makes a difference.  You could also try to do some
arithmetic comparisons with the double value, like:
   double ti = [timer timeInterval];
   if (ti < 0.9) printf(...);
   else if (ti < 1.0) printf(...);
   else if (ti < 1.01) printf(...);
   else printf(...);

and see what happens.  It's possible difference processors have
different behavior wrt converting, say, a 0.999999999 value to an int. 
It's also possible that such a difference, if true, is perfectly
legitimate (that is, within the bounds of undefined or unspecified
behavior in C).  [I don't remember any more if you said whether or not
you are using the same compiler on the two machines, or the same
binary.]


Chris Kane
Cocoa Frameworks, Apple
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

Related mailsAuthorDate
mlNSTimer or double to int cast (Bug?) Marco Binder Jan 9, 19:50
mlRe: NSTimer or double to int cast (Bug?) Cameron Hayne Jan 10, 08:55
mlRe: NSTimer or double to int cast (Bug?) Marco Binder Jan 10, 14:05
mlRe: NSTimer or double to int cast (Bug?) Cameron Hayne Jan 10, 16:07
mlRe: NSTimer or double to int cast (Bug?) Marco Binder Jan 10, 16:29
mlRe: NSTimer or double to int cast (Bug?) Chris Ridd Jan 10, 16:49
mlRe: NSTimer or double to int cast (Bug?) Dave Camp Jan 10, 17:39
mlRe: NSTimer or double to int cast (Bug?) Marco Binder Jan 10, 17:51
mlRe: NSTimer or double to int cast (Bug?) Chris Kane Jan 10, 21:03
mlRe: NSTimer or double to int cast (Bug?) Dietmar Planitzer Jan 10, 21:05
mlRe: Re: NSTimer or double to int cast (Bug?) Cameron Hayne Jan 10, 21:25
mlRe: NSTimer or double to int cast (Bug?) Chris Ridd Jan 11, 09:47
mlRe: NSTimer or double to int cast (Bug?) Marco Binder Jan 11, 15:35
mlRe: NSTimer or double to int cast (Bug?) Chris Ridd Jan 11, 16:33
mlRe: NSTimer or double to int cast (Bug?) Marco Binder Jan 11, 17:49
mlRe: NSTimer or double to int cast (Bug?) Dietmar Planitzer Jan 11, 23:21