IPv6 addresses are 128-bit unsigned integers under the hood, so their range of values is [0, 3.40 × 10^38]
A 128-bit register can store 2^128 (over 3.40 × 10^38) different values. The range of integer values that can be stored in 128 bits depends on the integer representation used. With the two most common representations, the range is 0 through 340,282,366,920,938,463,463,374,607,431,768,211,455 (2^128 − 1) for representation as an (unsigned) binary number, https://en.wikipedia.org/wiki/128-bit
A double-precision float variable in whatever language, though, can be as high as ±1.79769313486231570e+308 , so it definitely can assume all the values a 128-bit int can, and even more.
I'm sure there is a ready-to-use function/library/piece of code to convert from IPv6 => double. Can anyone post code to do that, or a link?
Thanks
Preferably PHP, but you can post code in other languages and i will translate to PHP.
P.S. i've read this related question Can double be used to store and safely retrieve 128 bit IPv6? but IMO the answers were wrong, because you don't need a variable with the same bits as the IPv6 address (128-bit). You just need it to be able to assume all the possible values an IPv6 can have. As i said above, a double can represent al the possible values of an 128-bit int and even more, despite it being just 64-bit.
How's that possible?
This is the magic of floating-point registers. They are more CPU-intensive to do calculations with compared to integer ones, but are more powerful.
EDIT: Why do i need this conversion: i have a MySQL table with IPv6 addresses defined as DECIMAL(39), which is a 39-digit int. I need to query that table by visitor's address if it is IPv6.