Skip to content

Instantly share code, notes, and snippets.

@breuderink
Created April 24, 2017 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save breuderink/a7e6fa9dffd57dc44779e4ab90865d32 to your computer and use it in GitHub Desktop.
Save breuderink/a7e6fa9dffd57dc44779e4ab90865d32 to your computer and use it in GitHub Desktop.
halton.go
package main
import (
"fmt"
)
func main() {
// Implementation of baseline fixed-point algorithm in [1].
//
// [1] Kolář, Miroslav, and Seamus F. O'Shea. "Fast, portable, and
// reliable algorithm for the calculation of Halton numbers." Computers
// & Mathematics with Applications 25.7 (1993): 3-13.
base := 3
var x, y int
var n, d int = 0, 1
for i := 0; i < 20; i++ {
x = d - n
if x == 1 {
n, d = 1, base*d
} else {
y = d / base
for x <= y {
y = y / base
}
n = (base+1)*y - x
}
fmt.Printf("H_%03d = %2d/%2d = %.4f\n", i, n, d,
float32(n)/float32(d))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment