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:
@@ -5,7 +5,8 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "mkdir -p build && go build -o build/argon ./src",
|
"build": "mkdir -p build && go build -o build/argon ./src",
|
||||||
"dev": "nodemon -x go run ./src/. --signal SIGKILL -e go --verbose"
|
"dev": "nodemon -x go run ./src/. --signal SIGKILL -e go --verbose",
|
||||||
|
"start": "go run ./src/."
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -3,5 +3,6 @@ package main
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
translate("")
|
||||||
fmt.Println("hello world")
|
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