Skip to content

BigDecimal#sqrt precision too high #354

Description

@tompng
x = BigDecimal('1.'+'1'*1000)
x.precision #=> 1001
x.sqrt(200).precision #=> expected: 200+extra, actual: 1126

Actual problem

x=BigDecimal('3.14')
100.times{
  x = x.sqrt(200)
  p x.precision
}

# Expect output
208
213
209
210
208
209
...(completes in about 0.03s)

# Actual output
208
226
253
289
...
9504
10567
11736
...(does not end)

Workaround
x.sqrt(prec).mult(1, prec)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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