James Maxwell wrote:

Now, when I run the calculation "live" and try to compare to my stored constants, I'm not getting matches. I'm assuming this is because the result of the calculation *isn't* actually what I stored in my constants, since the constants were rounded during the NSLog. So, how do I make sure my "live" calculation returns a value that will be rounded in the same way as an NSLog(@"%f", aFloat)?

Maybe you're trying to solve the wrong problem.

Just because you have a constant float doesn't mean it has to be:
  extern const float Foo;

It could also be:
 #define Foo (Foo_Value())
  extern float Foo_Value();

Then you run some initializing code that calculates your "constant" values and stores them in static variables to be returned by the functions. E.g.:

  static float const_Foo;

  extern float Foo_Value() { return const_Foo;  }

  extern void initializeConstants()
  { const_Foo = calc_Foo();  ..calculate and store other results.. }

You could use inline functions, too, if that's your thing.

Whether an approach like this is sufficient to avoid problems with rounding error and precision loss, only you can say, because you haven't explained anything about the actual calculations.

  -- GG

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please 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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to