Skip to content

Latest commit

 

History

History
38 lines (31 loc) · 1.14 KB

README.md

File metadata and controls

38 lines (31 loc) · 1.14 KB

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)