WARNING! Firebird Arithmetic

Problem:


select current_timestamp,

(current_timestamp - 1) as Minus1day, /* OK */

(current_timestamp - 1.0/2) as Minus12hour, /* OK */

(current_timestamp - 1.0/3) as Minus8hour, /* Err */

(current_timestamp - 1.0/4) as Minus6hour, /* Err */

(current_timestamp - 1.0/6) as Minus4hour, /* Err */

(current_timestamp - 1.0/12) as Minus2hour, /* Err */

(current_timestamp - 1.0/24) as Minus1hour /* Err */

from rdb$database

Answer:


"You should use as 1.00000/24.0 or 1.0/24.0000000 to force FB to

sense the precision."


Conclusion:


select current_timestamp,

(current_timestamp - 1) as Minus1day, /* OK */

(current_timestamp - 1.0000000/2) as Minus12hour, /* OK */

(current_timestamp - 1.0000000/3) as Minus8hour, /* OK */

(current_timestamp - 1.0000000/4) as Minus6hour, /* OK */

(current_timestamp - 1.0000000/6) as Minus4hour, /* OK */

(current_timestamp - 1.0000000/12) as Minus2hour, /* OK */

(current_timestamp - 1.0000000/24) as Minus1hour /* OK */

from rdb$database



Example:


select 1.0/3, /* result 0.3 */

1.0000000/3 /* result 0.3333333 */

from rdb$database


(c) eMeL * utolsó módosítás: 2005.05.24