File tree 3 files changed +9
-7
lines changed
3 files changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -68,8 +68,11 @@ func TestLn(t *testing.T) {
68
68
69
69
func TestLog (t * testing.T ) {
70
70
val := gal .Log (gal .NewNumber (123456 ), gal .NewNumber (5 ))
71
- assert .Equal (t , "5.09152 " , val .String ())
71
+ assert .Equal (t , "5.09151 " , val .String ())
72
72
73
73
val = gal .Log (gal .NewNumber (- 123456 ), gal .NewNumber (5 ))
74
74
assert .Equal (t , "undefined: Log:cannot calculate natural logarithm for negative decimals" , val .String ())
75
+
76
+ val = gal .Log (gal .NewNumber (10_000_000 ), gal .NewNumber (0 ))
77
+ assert .Equal (t , "7" , val .String ())
75
78
}
Original file line number Diff line number Diff line change @@ -266,7 +266,6 @@ func TestNestedFunctions(t *testing.T) {
266
266
// If renaming this test, also update the README.md file, where it is mentioned.
267
267
func TestMultiValueFunctions (t * testing.T ) {
268
268
expr := `sum(div(triple(7) double(4)))`
269
- parsedExpr := gal .Parse (expr )
270
269
271
270
// step 1: define funcs and vars and Eval the expression
272
271
funcs := gal.Functions {
@@ -297,7 +296,7 @@ func TestMultiValueFunctions(t *testing.T) {
297
296
"div" : func (args ... gal.Value ) gal.Value {
298
297
// returns the division of value1 by value2 as the interger portion and the remainder
299
298
if len (args ) != 2 {
300
- return gal .NewUndefinedWithReasonf ("mult () requires two arguments, got %d" , len (args ))
299
+ return gal .NewUndefinedWithReasonf ("div () requires two arguments, got %d" , len (args ))
301
300
}
302
301
303
302
dividend := args [0 ].(gal.Numberer ).Number ()
@@ -328,7 +327,7 @@ func TestMultiValueFunctions(t *testing.T) {
328
327
},
329
328
}
330
329
331
- got := parsedExpr .Eval (
330
+ got := gal . Parse ( expr ) .Eval (
332
331
gal .WithFunctions (funcs ),
333
332
)
334
333
expected := gal .NewNumber (7 )
Original file line number Diff line number Diff line change @@ -371,18 +371,18 @@ func (n Number) Ln(precision int32) Value {
371
371
}
372
372
373
373
func (n Number ) Log (precision int32 ) Value {
374
- res1 , err := n .value .Ln (precision )
374
+ res , err := n .value .Ln (precision + 1 )
375
375
if err != nil {
376
376
return NewUndefinedWithReasonf ("Log:" + err .Error ())
377
377
}
378
378
379
- res10 , err := decimal .New (10 , 0 ).Ln (precision )
379
+ res10 , err := decimal .New (10 , 0 ).Ln (precision + 1 )
380
380
if err != nil {
381
381
return NewUndefinedWithReasonf ("Log:" + err .Error ())
382
382
}
383
383
384
384
return Number {
385
- value : res1 .Div (res10 ).Truncate (precision ),
385
+ value : res .Div (res10 ).Truncate (precision ),
386
386
}
387
387
}
388
388
You can’t perform that action at this time.
0 commit comments