out !== a
(a, two_y_plus_x *Decimal, precision, max_steps, step *int256, gas *uint64)
| 504 | |
| 505 | // out !== a |
| 506 | func ln_recur(a, two_y_plus_x *Decimal, precision, max_steps, step *int256, gas *uint64) *Decimal { |
| 507 | var out Decimal |
| 508 | |
| 509 | // (2*step-1)*(2+x) |
| 510 | stepDec := createDecimal(step, ZERO_INT256, gas) |
| 511 | stepDec.Mul(stepDec, TWO_DECIMAL, precision, gas) |
| 512 | stepDec.Add(stepDec, MINUS_ONE_DECIMAL, precision, gas) |
| 513 | out.Mul(stepDec, two_y_plus_x, precision, gas) |
| 514 | |
| 515 | // end recursion? |
| 516 | if Cmp(max_steps, step, gas) == 0 { |
| 517 | return &out |
| 518 | } |
| 519 | |
| 520 | // recursion |
| 521 | Add(step, ONE_INT256, step, gas) |
| 522 | r := ln_recur(a, two_y_plus_x, precision, max_steps, step, gas) |
| 523 | Sub(step, ONE_INT256, step, gas) |
| 524 | r.Inv(r, precision, gas) |
| 525 | |
| 526 | // (step*x)^2 |
| 527 | stepDec2 := createDecimal(step, ZERO_INT256, gas) |
| 528 | stepDec2.Mul(stepDec2, a, precision, gas) |
| 529 | stepDec2.Mul(stepDec2, stepDec2, precision, gas) |
| 530 | |
| 531 | r.Mul(stepDec2, r, precision, gas) |
| 532 | r.Neg(r, gas) |
| 533 | |
| 534 | out.Add(&out, r, precision, gas) |
| 535 | |
| 536 | return &out |
| 537 | } |