cocoa - DBL_MAX & Max value of a double -


this line:

nslog(@"dbl_max: %f", dbl_max); 

prints large value: 17976931348623157081452742373170435679807056752584499659891747680315726078002853876058955863276687817154045895351438246423432132688946418276846754670353751698604991057655128207624549009038932894407586850845513394230458323690322294816580855933212334827479

however, when test double value this:

double test = 9999999999999999.0; nslog(@"test: %f", test); 

i unexpected result:

test: 10000000000000000.000000

this appears maximum number of digits produce expected result:

double test = 999999999999999.0; nslog(@"test: %f", test); 

test: 999999999999999.000000

how can work higher positive fractions?

thanks.

unfortunately, can't answer question directly, don't understand mean "how can work higher positive fractions?".

however, can shed light on floating-point number ans isn't.

a floating-point number consists of:

  • a sign (plus or minus)
  • an exponent
  • a value (known "mantissa").

these combined using clever encoding typically 32, 64, 80, or 128 bits. in addition, special encodings used represent +-infinity, not number (nan), , +-zero.

as mantissa has limited number of bits, value can have number of significant bits. small floating-point number can represent values in 10^-308 , and large 1 10^308. however, number can have 16 decimal digits.

on other words, print-out if dbl_max not corresponds amount of information stored in variable. example, there no way represent same number ...7480 instead of ...7479 @ end.

so question, in order tell how represent values, must describe kind of values want represent. fractions (i.e. 1 integer divided integer), in case might want represent using 2 integers. if want represent large values, might want use packages http://gmplib.org


Comments