Skip to main content

Accurately Converting NSString to GLFloat - iPhone



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.


Comments

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

    [str floatValue];
    [str doubleValue];

    ReplyDelete
  2. maybe this: NSString to NSNumber could help.

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...