Log10 sets d to the base 10 log of x.
(d, x *Decimal)
| 846 | |
| 847 | // Log10 sets d to the base 10 log of x. |
| 848 | func (c *Context) Log10(d, x *Decimal) (Condition, error) { |
| 849 | if set, res, err := c.logSpecials(d, x); set { |
| 850 | return res, err |
| 851 | } |
| 852 | |
| 853 | // TODO(mjibson): This is exact under some conditions. |
| 854 | res := Inexact |
| 855 | |
| 856 | nc := BaseContext.WithPrecision(c.Precision + 2) |
| 857 | nc.Rounding = RoundHalfEven |
| 858 | var z Decimal |
| 859 | _, err := nc.Ln(&z, x) |
| 860 | if err != nil { |
| 861 | return 0, fmt.Errorf("ln: %w", err) |
| 862 | } |
| 863 | nc.Precision = c.Precision |
| 864 | |
| 865 | qr, err := nc.Mul(d, &z, decimalInvLn10.get(c.Precision+2)) |
| 866 | if err != nil { |
| 867 | return 0, err |
| 868 | } |
| 869 | res |= qr |
| 870 | return c.goError(res) |
| 871 | } |
| 872 | |
| 873 | // Exp sets d = e**x. |
| 874 | func (c *Context) Exp(d, x *Decimal) (Condition, error) { |