How do you efficiently store very large and very small numbers from say 10^-100 to 10^100, so that you can use them to calculate values in a programming language like JavaScript.
JavaScript stores 10^100 as 1e+101, is there a way to do that in the database? The numbers would not often be that large, but I would like to do calculations with data such as 10^-34 * 2^16 or whatever, so the database should (I think) be storing these as numbers…
How does this work? How do you store numbers of this scale such that you can run computations with them?
By “the database”, I’m thinking in general. I am messing around with MongoDB and Neo4j currently.
Databases themselves don’t support numbers of arbitrary size in a native numeric format. Your general upper limit on numeric types is usually 8 bytes, which isn’t anywhere near a googol.
You’ll have to store the number either as a string (least efficient, easiest to work with, can be as precise as needed), as a byte array of arbitrary length (more efficient, harder to work with, still arbitrary precision), or in scientific notation (most efficient, harder to work with, and limited precision).
The first two, unfortunately, do eliminate the possibility of doing any server-side computation, since there wouldn’t be a native numeric type that could support the range of valid values. All of the computation would have to be done client-side using a suitable numeric type.