1

I need to find out what is the min and max value for a double field in mongoDB, including the number of precision for it.

I found this link: http://bsonspec.org/spec.html

Because MongoDB uses BSon, I'm looking for the BSON information. There is says:

double 8 bytes (64-bit IEEE 754-2008 binary floating point)

But how do I calculate the min and max number based on that?

I ended up at this link: https://en.wikipedia.org/wiki/Double-precision_floating-point_format

But couldn't understand how to calculate the min and max values.

Igor
  • 1,397
  • 3
  • 24
  • 56
  • are you looking for: it is approximately 10^308? or are you looking for a way to get that value in your code? most programming languages that use 64-bit IEEE754 floating point numbers have a constant available somewhere that you can use ([js for example](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE)) – kmdreko Dec 17 '18 at 23:03
  • relevant: https://stackoverflow.com/questions/10108053/ranges-of-floating-point-datatype-in-c – kmdreko Dec 17 '18 at 23:06
  • 1
    I need to know the min and max number accepted by mongodb. Like the min number is -999.9999 and max number is 999.9999. But I didn't understand how to calculate that – Igor Dec 17 '18 at 23:06
  • @kmdreko on the link you sent it brings me to a table with the explanation. But I still don't understand how to get to the specific values yet. Double on mongodb is a 64-bit IEEE 754-2008 binary floating point, which mean that it follow this standard. – Igor Dec 17 '18 at 23:13

1 Answers1

3

The wikipedia link you include has the precise answer:

min: -2^1023 * (1 + (1 − 2^−52))   (approx: -1.7976931348623157 * 10^308)
max:  2^1023 * (1 + (1 − 2^−52))   (approx:  1.7976931348623157 * 10^308)
kmdreko
  • 42,554
  • 6
  • 57
  • 106