Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
cmathexp()和log()函数总是对称的吗?
exp()
log()
因此,如果我这样做
double x; double y = exp(log(x)); assert(x == y);
断言是否会失败,在这种情况下:在什么情况下?我们可以假设这x是一个有理数 > 0。
x
浮点数log不能是一对一的。它需要单调递增并满足log(64) > 4.15和log(128) < 4.86。在 64 和 128 之间有 2 52 s,但在 4.15 和 4.86 之间double有不到 2 50 s。 double该范围内有多个doubles具有相同的双精度对数,因此exp(log(x)) == x至少其中一个必须失败。
log
log(64) > 4.15
log(128) < 4.86
double
doubles
exp(log(x)) == x
它们并不比*和更对称/。处理浮点数时会出现舍入误差,因此第 15 位(x左右y)可能会有所不同。
*
/
y