Add std.exponent and std.mantissa

This commit is contained in:
Stanisław Barzowski 2017-09-11 10:23:03 -04:00 committed by Dave Cunningham
parent ad4be04fc1
commit a94b877d4b
29 changed files with 38 additions and 0 deletions

View File

@ -404,6 +404,14 @@ var builtinAcos = liftNumeric(math.Acos)
var builtinAtan = liftNumeric(math.Atan) var builtinAtan = liftNumeric(math.Atan)
var builtinLog = liftNumeric(math.Log) var builtinLog = liftNumeric(math.Log)
var builtinExp = liftNumeric(math.Exp) var builtinExp = liftNumeric(math.Exp)
var builtinMantissa = liftNumeric(func(f float64) float64 {
mantissa, _ := math.Frexp(f)
return mantissa
})
var builtinExponent = liftNumeric(func(f float64) float64 {
_, exponent := math.Frexp(f)
return float64(exponent)
})
func liftBitwise(f func(int64, int64) int64) func(*evaluator, potentialValue, potentialValue) (value, error) { func liftBitwise(f func(int64, int64) int64) func(*evaluator, potentialValue, potentialValue) (value, error) {
return func(e *evaluator, xp, yp potentialValue) (value, error) { return func(e *evaluator, xp, yp potentialValue) (value, error) {
@ -604,6 +612,8 @@ var funcBuiltins = map[string]evalCallable{
"atan": &UnaryBuiltin{name: "atan", function: builtinAtan, parameters: ast.Identifiers{"x"}}, "atan": &UnaryBuiltin{name: "atan", function: builtinAtan, parameters: ast.Identifiers{"x"}},
"log": &UnaryBuiltin{name: "log", function: builtinLog, parameters: ast.Identifiers{"x"}}, "log": &UnaryBuiltin{name: "log", function: builtinLog, parameters: ast.Identifiers{"x"}},
"exp": &UnaryBuiltin{name: "exp", function: builtinExp, parameters: ast.Identifiers{"x"}}, "exp": &UnaryBuiltin{name: "exp", function: builtinExp, parameters: ast.Identifiers{"x"}},
"mantissa": &UnaryBuiltin{name: "mantissa", function: builtinMantissa, parameters: ast.Identifiers{"x"}},
"exponent": &UnaryBuiltin{name: "exponent", function: builtinExponent, parameters: ast.Identifiers{"x"}},
"pow": &BinaryBuiltin{name: "pow", function: builtinPow, parameters: ast.Identifiers{"base", "exp"}}, "pow": &BinaryBuiltin{name: "pow", function: builtinPow, parameters: ast.Identifiers{"base", "exp"}},
"modulo": &BinaryBuiltin{name: "modulo", function: builtinModulo, parameters: ast.Identifiers{"x", "y"}}, "modulo": &BinaryBuiltin{name: "modulo", function: builtinModulo, parameters: ast.Identifiers{"x", "y"}},
} }

1
testdata/std.exponent.golden vendored Normal file
View File

@ -0,0 +1 @@
0

1
testdata/std.exponent.input vendored Normal file
View File

@ -0,0 +1 @@
std.exponent(0)

1
testdata/std.exponent2.golden vendored Normal file
View File

@ -0,0 +1 @@
6

1
testdata/std.exponent2.input vendored Normal file
View File

@ -0,0 +1 @@
std.exponent(42)

1
testdata/std.exponent3.golden vendored Normal file
View File

@ -0,0 +1 @@
100

1
testdata/std.exponent3.input vendored Normal file
View File

@ -0,0 +1 @@
std.exponent(1e30)

1
testdata/std.exponent4.golden vendored Normal file
View File

@ -0,0 +1 @@
31

1
testdata/std.exponent4.input vendored Normal file
View File

@ -0,0 +1 @@
std.exponent(1 << 30)

1
testdata/std.exponent5.golden vendored Normal file
View File

@ -0,0 +1 @@
36

1
testdata/std.exponent5.input vendored Normal file
View File

@ -0,0 +1 @@
std.exponent(42 << 30)

1
testdata/std.exponent6.golden vendored Normal file
View File

@ -0,0 +1 @@
-24

1
testdata/std.exponent6.input vendored Normal file
View File

@ -0,0 +1 @@
std.exponent(42 / (1 << 30))

1
testdata/std.exponent7.golden vendored Normal file
View File

@ -0,0 +1 @@
6

1
testdata/std.exponent7.input vendored Normal file
View File

@ -0,0 +1 @@
std.exponent(-42)

1
testdata/std.mantissa.golden vendored Normal file
View File

@ -0,0 +1 @@
0

1
testdata/std.mantissa.input vendored Normal file
View File

@ -0,0 +1 @@
std.mantissa(0)

1
testdata/std.mantissa2.golden vendored Normal file
View File

@ -0,0 +1 @@
0.65625

1
testdata/std.mantissa2.input vendored Normal file
View File

@ -0,0 +1 @@
std.mantissa(42)

1
testdata/std.mantissa3.golden vendored Normal file
View File

@ -0,0 +1 @@
0.83999999999999997

1
testdata/std.mantissa3.input vendored Normal file
View File

@ -0,0 +1 @@
std.mantissa(0.42)

1
testdata/std.mantissa4.golden vendored Normal file
View File

@ -0,0 +1 @@
0.5714936956411375

1
testdata/std.mantissa4.input vendored Normal file
View File

@ -0,0 +1 @@
std.mantissa(1e100)

1
testdata/std.mantissa5.golden vendored Normal file
View File

@ -0,0 +1 @@
0.65625

1
testdata/std.mantissa5.input vendored Normal file
View File

@ -0,0 +1 @@
std.mantissa(42 << 30)

1
testdata/std.mantissa6.golden vendored Normal file
View File

@ -0,0 +1 @@
0.65625

1
testdata/std.mantissa6.input vendored Normal file
View File

@ -0,0 +1 @@
std.mantissa(42 / (1 << 30))

1
testdata/std.mantissa7.golden vendored Normal file
View File

@ -0,0 +1 @@
-0.65625

1
testdata/std.mantissa7.input vendored Normal file
View File

@ -0,0 +1 @@
std.mantissa(-42)