MCPcopy Create free account
hub / github.com/cockroachdb/apd / Log10

Method Log10

context.go:848–871  ·  view source on GitHub ↗

Log10 sets d to the base 10 log of x.

(d, x *Decimal)

Source from the content-addressed store, hash-verified

846
847// Log10 sets d to the base 10 log of x.
848func (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.
874func (c *Context) Exp(d, x *Decimal) (Condition, error) {

Callers 3

RunMethod · 0.45
TestErrDecimalFunction · 0.45
ExpMethod · 0.45

Calls 6

logSpecialsMethod · 0.95
goErrorMethod · 0.95
WithPrecisionMethod · 0.80
getMethod · 0.80
LnMethod · 0.45
MulMethod · 0.45

Tested by 2

RunMethod · 0.36
TestErrDecimalFunction · 0.36