Forum Stats

  • 3,871,965 Users
  • 2,266,360 Discussions
  • 7,911,017 Comments

Discussions

MOD function with embedded LOG function gives an incorrect result

MOD(LOG(2,4),1) = 1

How is this possible?


Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

PL/SQL Release 12.2.0.1.0 - Production

CORE 12.2.0.1.0 Production

TNS for Linux: Version 12.2.0.1.0 - Production

NLSRTL Version 12.2.0.1.0 - Production

Tagged:

Answers

  • Stax
    Stax Member Posts: 184 Silver Badge
    SQL> col l format 9.9999999999999999999999999999999999999999999999
    SQL> select LOG(2,4) l  from dual
      2  /
    
    
                                                    L
    -------------------------------------------------
     1.9999999999999999999999999999999999999800000000
    
    
    SQL>
    


    User_8MZ3Y
  • User_8MZ3Y
    User_8MZ3Y Member Posts: 3 Green Ribbon

    I was trying to resolve this. I found there is no problem with mod function, but there is a problem with log function.

    SELECT LOG(2,4) FROM DUAL -> 2

    SELECT TO_CHAR(LOG(2,4)) FROM DUAL -> 1,99999999999999999999999999999999999998

  • User_8MZ3Y
    User_8MZ3Y Member Posts: 3 Green Ribbon

    Sorry Stax, I didn't read your answer. Yes, the real problem is LOG function.

  • Solomon Yakobson
    Solomon Yakobson Member Posts: 19,908 Red Diamond

    Precision games :)

    SQL> col l format 9.9999999999999999999999999999999999999999999999
    SQL> select LOG(2,4) l from dual;
                                                    L
    -------------------------------------------------
     1.9999999999999999999999999999999999999800000000
    
    SQL> select LOG(cast(2 as binary_float),4) l from dual; -- or binary_double for more precision
                                                    L
    -------------------------------------------------
     2.0000000000000000000000000000000000000000000000
    
    SQL>
    

    SY.