• 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: James Bucanek <email@hidden>
  • Date: Sat, 27 Jan 2007 09:07:38 -0700

Gilles Celli wrote on Saturday, January 27, 2007:
>I need to convert NSDate to a meaningful NSPoint for the x-Axis of my
>plotting application, so that the graph plots
>the points to the corresponding time of the current day.
<clip>
>
>[Result]
>
>2007-01-26 18:09:30.599 AcquiKeithley[11852] acqDate as timeInterval:
>191524170.000177 | graphData.x = 191524176.000000   =============>
>different value !!!!
>
>2007-01-26 18:09:30.600 AcquiKeithley[11852] acqDate as timeInterval:
>191524170.500054 | graphData.x = 191524176.000000  =============>
>different value !!!!
>
>[Result]
>
>So you see I get a different values. I tried to do a cast to (float)
>but it didn't work.
>I'm sure that I'm making something wrong.... :-(

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

  • Follow-Ups:
    • Re: Strange results when converting NSDate timeIntervalSinceReferenceDate to NSPoint
      • From: Gilles Celli <email@hidden>
References: 
 >Strange results when converting NSDate timeIntervalSinceReferenceDate to NSPoint (From: Gilles Celli <email@hidden>)

  • Prev by Date: Core Data: Role of transient attributes with derived and non-standard attributes?
  • Next by Date: NSAlert, NSRunPanel Issues
  • Previous by thread: Strange results when converting NSDate timeIntervalSinceReferenceDate to NSPoint
  • Next by thread: Re: Strange results when converting NSDate timeIntervalSinceReferenceDate to NSPoint
  • Index(es):
    • Date
    • Thread