Skip to content

Rational to BigDecimal conversion precision too low in add, sub and mult #388

@tompng

Description

@tompng
# BASE_FIG=9 (defined(HAVE_INT64_T) == true)
BigDecimal(1).add(1/3r, 1000) #=> 0.1333333333e1
BigDecimal(1).sub(1/3r, 1000) #=> 0.666666667e0
BigDecimal(1).mult(1/3r, 1000) #=> 0.333333333e0
BigDecimal(0) + 1/3r #=> 0.333333333e0

# BASE_FIG=4 (defined(HAVE_INT64_T) == false)
BigDecimal(1).add(1/3r, 1000) #=> 0.13333e1
BigDecimal(1).sub(1/3r, 1000) #=> 0.6667e0
BigDecimal(1).mult(1/3r, 1000) #=> 0.3333e0
BigDecimal(0) + 1/3r #=> 0.3333e0

Expected:

BigDecimal(1).div(3/7r, 100)
#=> 0.2333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333e1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions