Created
April 24, 2017 19:59
-
-
Save breuderink/a7e6fa9dffd57dc44779e4ab90865d32 to your computer and use it in GitHub Desktop.
halton.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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