Browse Source

fix: Including NaN and Inf functions in stdlib by default

Matthias Ladkau 3 years ago
parent
commit
6f56203e58
2 changed files with 12 additions and 4 deletions
  1. 2 2
      stdlib/generate/generate.go
  2. 10 2
      stdlib/stdlib_gen.go

+ 2 - 2
stdlib/generate/generate.go

@@ -49,7 +49,7 @@ go list std | grep -v internal | grep -v '\.' | grep -v unsafe | grep -v syscall
 // =============EDIT HERE START=============
 
 var pkgNames = map[string][]string{
-	//	"math": {"Pi", "E", "Phi", "Pow"},
+	//	"math": {"Pi", "E", "Phi", "Inf", "IsInf", "IsNaN"},
 	//	"fmt":  {"Println", "Sprint"},
 }
 
@@ -74,7 +74,7 @@ func main() {
 	// Make sure we have at least an empty pkgName
 
 	if len(pkgNames) == 0 {
-		pkgNames["math"] = []string{"Pi", "E", "Phi"}
+		pkgNames["math"] = []string{"Pi", "E", "Phi", "Inf", "IsInf", "IsNaN"}
 	}
 
 	// Make sure pkgNames is sorted

+ 10 - 2
stdlib/stdlib_gen.go

@@ -30,12 +30,20 @@ var mathConstMap = map[interface{}]interface{}{
 /*
 mathFuncDocMap contains the documentation of stdlib math functions.
 */
-var mathFuncDocMap = map[interface{}]interface{}{}
+var mathFuncDocMap = map[interface{}]interface{}{
+	"Inf":   "Function: Inf",
+	"IsInf": "Function: IsInf",
+	"IsNaN": "Function: IsNaN",
+}
 
 /*
 mathFuncMap contains the mapping of stdlib math functions.
 */
-var mathFuncMap = map[interface{}]interface{}{}
+var mathFuncMap = map[interface{}]interface{}{
+	"Inf":   &ECALFunctionAdapter{reflect.ValueOf(math.Inf), fmt.Sprint(mathFuncDocMap["Inf"])},
+	"IsInf": &ECALFunctionAdapter{reflect.ValueOf(math.IsInf), fmt.Sprint(mathFuncDocMap["IsInf"])},
+	"IsNaN": &ECALFunctionAdapter{reflect.ValueOf(math.IsNaN), fmt.Sprint(mathFuncDocMap["IsNaN"])},
+}
 
 // Dummy statement to prevent declared and not used errors
 var Dummy = fmt.Sprint(reflect.ValueOf(fmt.Sprint))