ln(x*y)=ln(x)+ln(y)
x*y =eln(x*y)=eln(x)+ln(y)
ln(x/y)=ln(x)-ln(y)
x/y =eln(x/y)=eln(x)-ln(y)
對於對數的真數是必須>0的數 所以對於負數相乘的時候要求絕對值(負數加個符號就可以),再求得對數後再加上符號,對於0相乘等於0就可以。
對於oracle 的sql爲 exp(ln(x)+ln(y))
select case
when t1.x > 1 then
case
when t1.y > 1 then
exp(ln(t1.x) + ln(t1.y))
when t1.y = 0 then
0.0
when t1.y < 0 then
-exp(ln(t1.x) + ln(-t1.y))
end
when t1.x = 0 then
0.0
when t1.x < 0 then
case
when t1.y > 1 then
-exp(ln(-t1.x) + ln(t1.y))
when t1.y = 0 then
0.0
when t1.y < 0 then
exp(ln(-t1.x) + ln(-t1.y))
end
end z -- z=x*y
from tempMul t1