0

Say I have some vertice values which I am reading into my app as a NSString :

-7501.6 -6198.2 834.939 -5547.66 -6348.32 2122.65

The values in the source are always 6 figures in length.

I need to pass these exact values to OpenGL. If I try to cast as a float (using NSString floatValue) then, as expected, I get an approximate value for each float due to the inexact nature of a float :

-7501.600098, -6198.200195, 834.939026 -5547.660156, -6348.319824, 2122.649902

Can anyone suggest a way that I can get these values into OpenGL and retain their exact initial integrity ?

Thank you.

mskfisher
  • 3,177
  • 3
  • 33
  • 47
GuybrushThreepwood
  • 5,549
  • 9
  • 53
  • 111
  • But even OpenGL will be using floats/doubles. If these values cannot be represented exactly as floating-point values, then you cannot do this. – Mike Weller May 31 '12 at 15:53

2 Answers2

0

maybe this: NSString to NSNumber could help.

Community
  • 1
  • 1
CarlJ
  • 9,401
  • 3
  • 32
  • 46
-1

See 'Getting Numeric Values' paragraph from NSString Documentation (Apple).

[str floatValue]; [str doubleValue];

hburde
  • 1,441
  • 11
  • 6