Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Accuracy of the log function
Dear all,
I've tried to write a function to determine the number of bits of an integer, the implementation is like this:
FUNCTION bit_cnt
(pi_number NUMBER ) RETURN NUMBER IS
However, I found that the function return wrong result if the number is the power of 2 (i.e. 2, 4, 8, 16, 32, etc) and then discovered that the values returned by the LOG function on these values are actually 0.99999..., 1.99999..., 2.99999..., 3.9999..., 4.9999... etc. After the TRUNC function, the values returned by my function are 1, 2, 3, 4, 5, etc and obviously are wrong.
I believe that replacing the TRUNC by ROUND, FLOOR or CEIL will not solve the problem.
And I finally modified the function like this
FUNCTION bit_cnt
(pi_number NUMBER ) RETURN NUMBER IS
My question is that can we consider the behaviour of the LOG function as a bug ? Is there a better way to implement my function ?
Best regards,
O.K.Man Received on Wed Aug 29 2001 - 10:06:21 CDT
![]() |
![]() |