Compare commits
No commits in common. "8b88beae884cce7b78306c46342f5a7334496ed8" and "9dc6e1443d98c0e7a32277c7cd351872ecfa0c49" have entirely different histories.
8b88beae88
...
9dc6e1443d
13
f.go
13
f.go
|
@ -9,6 +9,7 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -88,7 +89,7 @@ const HELP_MSG = " Operation | Variable assignment | Special\n" +
|
||||||
" exit\n"
|
" exit\n"
|
||||||
const NORMAL90CONFIDENCE = 1.6448536269514727
|
const NORMAL90CONFIDENCE = 1.6448536269514727
|
||||||
const INIT_DIST Scalar = Scalar(1)
|
const INIT_DIST Scalar = Scalar(1)
|
||||||
const N_SAMPLES = 1_000_000
|
const N_SAMPLES = 100_000
|
||||||
|
|
||||||
/* Printers */
|
/* Printers */
|
||||||
func prettyPrintDist(dist Dist) {
|
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")
|
return parseWordsErr("Operator must have operand; can't operate on nothing")
|
||||||
case 1:
|
case 1:
|
||||||
var_word, var_word_exists := vars[words[0]]
|
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 {
|
switch {
|
||||||
case var_word_exists:
|
case var_word_exists:
|
||||||
dist = var_word
|
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")
|
return parseWordsErr("Trying to operate on a scalar, but scalar is neither a float nor an assigned variable")
|
||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
new_low, err1 := pretty.ParseFloat(words[0])
|
new_low, err1 := strconv.ParseFloat(words[0], 64)
|
||||||
new_high, err2 := pretty.ParseFloat(words[1])
|
new_high, err2 := strconv.ParseFloat(words[1], 64)
|
||||||
if err1 != nil || err2 != nil {
|
if err1 != nil || err2 != nil {
|
||||||
return parseWordsErr("Trying to operate by a distribution, but distribution is not specified as two floats")
|
return parseWordsErr("Trying to operate by a distribution, but distribution is not specified as two floats")
|
||||||
}
|
}
|
||||||
dist = Lognormal{low: new_low, high: new_high}
|
dist = Lognormal{low: new_low, high: new_high}
|
||||||
case 3:
|
case 3:
|
||||||
if words[0] == "beta" || words[0] == "b" {
|
if words[0] == "beta" || words[0] == "b" {
|
||||||
a, err1 := pretty.ParseFloat(words[1])
|
a, err1 := strconv.ParseFloat(words[1], 64)
|
||||||
b, err2 := pretty.ParseFloat(words[2])
|
b, err2 := strconv.ParseFloat(words[2], 64)
|
||||||
if err1 != nil || err2 != nil {
|
if err1 != nil || err2 != nil {
|
||||||
return parseWordsErr("Trying to specify a beta distribution? Try beta 1 2")
|
return parseWordsErr("Trying to specify a beta distribution? Try beta 1 2")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
package pretty
|
package pretty
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func PrettyPrintInt(n int) {
|
func PrettyPrintInt(n int) {
|
||||||
|
@ -51,37 +49,3 @@ func PrettyPrint2Floats(low float64, high float64) {
|
||||||
fmt.Printf(" ")
|
fmt.Printf(" ")
|
||||||
PrettyPrintFloat(high)
|
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user