plsql - The way oracle calculate mod(binary_float, 0) -


oracle document (http://docs.oracle.com/cd/b19306_01/server.102/b14200/functions088.htm#i77996) says "mod returns remainder of n2 divided n1. returns n2 if n1 0.". got unexpected result (i thought should 1.1 got 0) when put binary_float in n2.

sql> select mod(1.1,0), to_binary_float('1.1'), mod(to_binary_float('1.1'), 0) dual;  mod(1.1,0) to_binary_float('1.1') mod(to_binary_float('1.1'),0) ---------- ---------------------- -----------------------------        1.1               1.1e+000                             0 

does has idea?

interesting. think has floor vs round used internally in calculations.

for example, remainder function similar mod, except uses round instead of floor. example, return nan (not number):

select remainder(to_binary_float(1.1), 0) dual 

output:

nan 

whats more interesting can use nanvl function provide default value if nan returned (in case, mimic mod behavior , return 1.1), , return float value:

select nanvl(remainder(to_binary_float(1.1), 0), 1.1) dual 

output:

1.10000002384186 

so perhaps thats workaround.

hope helps


Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -