Skip to content

BigDecimal#to_f is slow when it has large n_significant_digits #515

@tompng

Description

@tompng

BigDecimal#to_f is accurate, it returns exact nearest float value, but may be extremely slow in some case.

irb(main):003> x = BigDecimal(1).div(7, 10000); 10000.times{(x - it).to_f}
processing time: 1.746866s
=> 10000
irb(main):004> x = BigDecimal(1).div(7, 10000); 10000.times{(x - it).mult(1, 20).to_f}
processing time: 0.053746s

If BigDecimal#to_f is optimized, we can remove workaround like #514

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