• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTimer or double to int cast (Bug?)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTimer or double to int cast (Bug?)


  • Subject: Re: NSTimer or double to int cast (Bug?)
  • From: Chris Kane <email@hidden>
  • Date: Fri, 10 Jan 2003 12:03:19 -0800

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@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: NSTimer or double to int cast (Bug?)
      • From: Marco Binder <email@hidden>
    • Re: NSTimer or double to int cast (Bug?)
      • From: Chris Ridd <email@hidden>
References: 
 >Re: NSTimer or double to int cast (Bug?) (From: Chris Ridd <email@hidden>)

  • Prev by Date: Re: Re: NSTimer or double to int cast (Bug?)
  • Next by Date: Using iconForFileType: to get an icon.
  • Previous by thread: Re: NSTimer or double to int cast (Bug?)
  • Next by thread: Re: NSTimer or double to int cast (Bug?)
  • Index(es):
    • Date
    • Thread