Skip to content

Convert numbers to radix strings, just like in JavaScript.

License

Notifications You must be signed in to change notification settings

CrimsonAIO/radix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

radix

Convert floats to radix strings, just the way JavaScript does it.

This does not call JavaScript code whatsoever. This is a completely native solution to Go.

Usage

package main

import (
	"fmt"
	"github.com/CrimsonAIO/radix"
)

func main() {
	// prints: 1.41b71758e2196
	// the same result can be achieved via calling "(1.2567).toString(16)" in JavaScript.
	fmt.Println(radix.ToString(1.2567, 16))
}

Check it out on The Go Playground.

Benchmarks

This benchmark was ran on an iMac with an M1 processor.

goos: darwin
goarch: arm64
pkg: github.com/CrimsonAIO/radix
BenchmarkConv
BenchmarkConv-8   	 3071470	       383.9 ns/op

If you wish to benchmark on your own system, clone this repository and run go test -bench .

Credits

The logic for this has been taken from Google's V8 engine. The source can be found at:
DoubleToRadixCString (main function)
double.h (double-uint64 utility)

About

Convert numbers to radix strings, just like in JavaScript.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages