Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As an alternative, there is also the NSDecimal struct for representing numerical types. NSDecimal (and its Objective-C class version NSDecimalNumber) lets you represent true decimals and avoid floating point errors, so it tends to be <a href="https://stackoverflow.com/questions/421463/should-i-use-nsdecimalnumber-to-deal-with-money">recommended for dealing with things like currency</a>.</p> <p>The NSDecimal struct can represent numbers as well as a Not a Number state (a potential nil replacement). You can query whether an NSDecimal is not a number using <code>NSDecimalIsNotANumber()</code>, and generate the Not a Number value with the help of an NSDecimalNumber.</p> <p>NSDecimals are <a href="https://stackoverflow.com/questions/1336083/memory-management-with-nsdecimalnumber-how-to-avoid-memory-problems-in-tight-loo/1336299#1336299">faster to work with than NSDecimalNumbers</a>, and the structs don't bring the same kind of memory management issues that objects do.</p> <p>However, there isn't an easy way to get values into NSDecimal form without using a temporary NSDecimalNumber. <strike>Also, many of the math functions (like trigonometry operations) that are available for simple floating point numbers aren't yet available for NSDecimal. I'd like to write my own functions that add some of these capabilities, but they would require accessing the internal fields of the struct. Apple labels these as private (with the use of an underscore), but they are present in the headers and I'd guess they're unlikely to change in the future.</strike></p> <p><strong>Update:</strong> Dave DeLong wrote a series of functions for performing NSDecimal trigonometry, roots, and other operations. I've tweaked these to provide up to 34 digits of decimal precision, and the code for these functions can be downloaded <a href="http://www.sunsetlakesoftware.com/sites/default/files/FixedDDDecimalFunctions.zip" rel="nofollow noreferrer">here</a>. As a warning, this precision comes at a price in terms of performance, but these functions should be fine for fairly infrequent calculations.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload