• 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: Strange results when converting NSDate timeIntervalSinceReferenceDate to NSPoint
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strange results when converting NSDate timeIntervalSinceReferenceDate to NSPoint


  • Subject: Re: Strange results when converting NSDate timeIntervalSinceReferenceDate to NSPoint
  • From: Gilles Celli <email@hidden>
  • Date: Mon, 29 Jan 2007 16:49:58 +0100

James,

Thanks a lot for your answer. It works as you described: I had to take the current Date as reference Date.

I wrote your answer and the solution on the SM2DGraphView forums:
http://www.snowmintcs.com/forums/viewtopic.php?p=3807#3807

Thanks for all your help.

Gilles Celli

On Jan 27, 2007, at 5:07 PM, James Bucanek wrote:


I'm certainly not an expert on floating point numbers, but I think the answer is simple: NSDates use doubles (64 bit floating point values) and NSPoint uses floats (32 bit floating point values).


A (single) float has 23 bits for the mantissa (the significant digits). That gives you an accuracy of about 7 decimal places. The double number you are trying to convert is 191524170.500054. The first 7 digits are 1915241xx.xxxx; the rest will be lost in conversion.

Since the origin of your graph probably isn't the reference date, the simple solution is to make the origin of your graph some recent date. Then x coordinates would be expressed as the difference between the graph's origin and the sample point, which is going to be a much smaller number. The smaller the number, the better the accuracy of the double to float conversion.

    (typed in mail)

NSDate* graphOriginDate = [NSDate ...]; // date of x axis origin
...
for (...)
{
graphData[iRow].x = (float)[k2700_str[iRow].acqDate timeIntervalSinceDate:graphOrginDate];
...
}


--
James Bucanek


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: Strange results when converting NSDate timeIntervalSinceReferenceDate to NSPoint (From: James Bucanek <email@hidden>)

  • Prev by Date: Re: Globally modify "new document" behavior in document-based applications
  • Next by Date: CoreData and nil values?
  • Previous by thread: Re: Strange results when converting NSDate timeIntervalSinceReferenceDate to NSPoint
  • Next by thread: Core Data: Role of transient attributes with derived and non-standard attributes?
  • Index(es):
    • Date
    • Thread