Menu

#697 floor and truncate round up for some numbers

lisp error
closed-invalid
None
5
2017-06-16
2017-06-16
Leo
No

(floor 13158008.6)
13158009
It should be 13158008.
Same with truncate.

Discussion

  • Bruno Haible

    Bruno Haible - 2017-06-16
    • labels: floor error -->
    • status: open --> closed-invalid
    • assigned_to: Bruno Haible
     
  • Bruno Haible

    Bruno Haible - 2017-06-16

    It's not the FLOOR function which rounds up, it's the parsing of the number:

    (rationalize 13158008.6) => 13158009
    read-default-float-format => SINGLE-FLOAT

    It you want more than 6 digits of precision with floating-point numbers, you need to force double-precision, either explicitly

    (floor 13158008.6d0) => 13158008 ; 0.599999999627471d0

    or by changing read-default-float-format :

    (setq read-default-float-format 'double-float) => DOUBLE-FLOAT
    (floor 13158008.6) => 13158008 ; 0.599999999627471d0

     

Log in to post a comment.

MongoDB Logo MongoDB