
谁能用php帮我解决掉这个问题,加分。
看你希望怎么解决,因为我们不知道你的约束条件在那里。但是可以做很多办法来补偿。
比如说在数据库层面,用两个整数字段,或者字符串字段来存储单个的整数。
比如说,数据库不能修改,但是可以通过编程语言做修正。
需要你先给出你的场景,还有代码,然后才好找到进一步的方法
C/C++直接用指针暴力转换就可以了。
不同的编译器对64bit的整数的支持不一样,以下代码在gcc编译
在线验证网址:https://c.runoob.com/compile/12
#include <stdio.h>
int main()
{
double d = -6.29187711124658e-311;
__int64_t *l = (__int64_t *)&d;
printf("%llu", *l);
return 0;
}
9223384771755824298
关键是Java,它不支持指针,所以没办法简单暴力,需要用BigInteger
代码如下:
import java.math.BigInteger;
public class HelloWorld {
public static void main(String []args) {
double d = -6.29187711124658e-311;
long value = Double.doubleToRawLongBits(d);
BigInteger bi = new BigInteger("0");
BigInteger base = new BigInteger("1");
Boolean sign = (value < 0);
if (value < 0)
{
value += 9223372036854775807L;
value += 1L;
}
while (value > 0)
{
bi = bi.add(new BigInteger(String.valueOf(value % 2)).multiply(base));
base = base.multiply(new BigInteger("2"));
value /= 2;
}
if (sign) bi = bi.add(new BigInteger("9223372036854775808"));
System.out.println(bi);
}
}
9223384771755824298
如果一种语言不支持 Double.doubleToRawLongBits 这样的方法
那么你可以根据IEEE标准的浮点数的格式自己去转换。
如果你还需要别的语言的例子,可以继续追问。
如果问题解决,麻烦采纳下,谢谢
下面是SQLite数据类型参考手册上关于这个问题的解释:
datatype reference in SQLite
INTEGER. The value is a signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value.
That is, you can only store values from -2**63 to (2**63-1). What does SQLite do for a value outside of this range? As we saw earlier, it switches over into floating point. Again, quoting from the SQLite reference:
REAL. The value is a floating point value, stored as an 8-byte IEEE floating point number.
Many programmers are familiar with this type under the name double.
PHP版本
<?php
$binarydata = pack("d", -3.68861248304756e-311);
$value = unpack("Q", $binarydata);
echo("float format: ");
echo($value[1] + pow(2, 64));
echo("\ninteger format: ");
$ofvalue = $value[1] + 9223372036854775808;
echo (" 92233");
echo ($ofvalue + 72036854775808);
?>
float format: 9.2233795026896E+18
integer format: 9223379502689557504