Home » Ios » What is the max. value of a double/float on iPhone?

What is the max. value of a double/float on iPhone?

Posted by: admin November 30, 2017 Leave a comment

Questions:

Does anybody know the values or the file that they’re defined in? Or a macro, like INT_MAX?

Answers:

I believe it’s in <float.h>: FLT_MAX, DBL_MAX, etc.

Questions:
Answers:

On the iOS simulator, I logged LONG_MAX, FLT_MAX and DBL_MAX. Here’s what I got:

long max value: 9223372036854775807
float max value: 340282346638528859811704183484516925440.000000
double max value: 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000

Side note, if you use NSNumber it uses the appropriate type to store your number.

Questions:
Answers:

If you need max value for CGFloat you should use safely defined CGFLOAT_MAX.