mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 08:56:07 +00:00
working on number type
This commit is contained in:
@@ -3,5 +3,6 @@ package main
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
translate("")
|
||||
fmt.Println("hello world")
|
||||
}
|
||||
|
||||
31
src/number.go
Normal file
31
src/number.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
// a number type
|
||||
type number = *big.Rat
|
||||
|
||||
// create a number from two integers
|
||||
var createNumber = big.NewRat
|
||||
|
||||
// create a new number type
|
||||
func newNumber() *big.Rat {
|
||||
return new(big.Rat)
|
||||
}
|
||||
|
||||
// converts a string into a number
|
||||
func stringToNumber(str string) (*big.Rat, bool) {
|
||||
return newNumber().SetString(str)
|
||||
}
|
||||
|
||||
// converts a number type to a string
|
||||
func numberToString(num number, fraction bool) string {
|
||||
if fraction {
|
||||
return num.RatString()
|
||||
}
|
||||
x, _ := num.Float64()
|
||||
return fmt.Sprint(x)
|
||||
}
|
||||
16
src/translate.go
Normal file
16
src/translate.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func translate(code string) {
|
||||
a := createNumber(7, 1)
|
||||
b, worked := stringToNumber("1e-1")
|
||||
if worked {
|
||||
output := newNumber().Mul(a, b)
|
||||
output.Add(output, a)
|
||||
output.Sub(output, a)
|
||||
fmt.Println(numberToString(output, true))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user