Compare commits

..

No commits in common. "8b88beae884cce7b78306c46342f5a7334496ed8" and "9dc6e1443d98c0e7a32277c7cd351872ecfa0c49" have entirely different histories.

2 changed files with 7 additions and 42 deletions

13
f.go
View File

@ -9,6 +9,7 @@ import (
"math"
"os"
"sort"
"strconv"
"strings"
)
@ -88,7 +89,7 @@ const HELP_MSG = " Operation | Variable assignment | Special\n" +
" exit\n"
const NORMAL90CONFIDENCE = 1.6448536269514727
const INIT_DIST Scalar = Scalar(1)
const N_SAMPLES = 1_000_000
const N_SAMPLES = 100_000
/* Printers */
func prettyPrintDist(dist Dist) {
@ -304,7 +305,7 @@ func parseWordsIntoOpAndDist(words []string, vars map[string]Dist) (string, Dist
return parseWordsErr("Operator must have operand; can't operate on nothing")
case 1:
var_word, var_word_exists := vars[words[0]]
single_float, err1 := pretty.ParseFloat(words[0]) // abstract this away to search for K/M/B/T/etc.
single_float, err1 := strconv.ParseFloat(words[0], 64) // abstract this away to search for K/M/B/T/etc.
switch {
case var_word_exists:
dist = var_word
@ -314,16 +315,16 @@ func parseWordsIntoOpAndDist(words []string, vars map[string]Dist) (string, Dist
return parseWordsErr("Trying to operate on a scalar, but scalar is neither a float nor an assigned variable")
}
case 2:
new_low, err1 := pretty.ParseFloat(words[0])
new_high, err2 := pretty.ParseFloat(words[1])
new_low, err1 := strconv.ParseFloat(words[0], 64)
new_high, err2 := strconv.ParseFloat(words[1], 64)
if err1 != nil || err2 != nil {
return parseWordsErr("Trying to operate by a distribution, but distribution is not specified as two floats")
}
dist = Lognormal{low: new_low, high: new_high}
case 3:
if words[0] == "beta" || words[0] == "b" {
a, err1 := pretty.ParseFloat(words[1])
b, err2 := pretty.ParseFloat(words[2])
a, err1 := strconv.ParseFloat(words[1], 64)
b, err2 := strconv.ParseFloat(words[2], 64)
if err1 != nil || err2 != nil {
return parseWordsErr("Trying to specify a beta distribution? Try beta 1 2")
}

View File

@ -1,10 +1,8 @@
package pretty
import (
"errors"
"fmt"
"math"
"strconv"
)
func PrettyPrintInt(n int) {
@ -51,37 +49,3 @@ func PrettyPrint2Floats(low float64, high float64) {
fmt.Printf(" ")
PrettyPrintFloat(high)
}
func multiplyOrPassThroughError(a float64, b float64, err error) (float64, error) {
if err != nil {
return b, err
} else {
return a * b, nil
}
}
func ParseFloat(word string) (float64, error) {
// l = len(word) // assuming no UTF stuff
switch len(word) {
case 0:
return 0, errors.New("String to be parsed into float must not be the empty string")
case 1:
return strconv.ParseFloat(word, 64)
}
n := len(word) - 1
f, err := strconv.ParseFloat(word[:n], 64)
switch word[n] {
case 'K':
return multiplyOrPassThroughError(1_000, f, err)
case 'M':
return multiplyOrPassThroughError(1_000_000, f, err)
case 'B':
return multiplyOrPassThroughError(1_000_000_000, f, err)
case 'T':
return multiplyOrPassThroughError(1_000_000_000_000, f, err)
default:
return strconv.ParseFloat(word, 64)
}
}