This file contains 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" | |
"math" | |
) | |
const float32MantissaMask = 0x7FFFFF | |
const float32ExponentMask = 0x7F800000 | |
const float32SignMask = 0x80000000 | |
const float32ExponentBitOffset = 23 |
This file contains 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
// Prints: | |
// 1 2 3 4 5 | |
// reverse | |
// 5 4 3 2 1 | |
package main | |
import ( | |
"fmt" | |
) |
This file contains 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
// farey rational approximation | |
package main | |
import ( | |
"fmt" | |
"math" | |
) | |
// x is value to find rational approximation of |
This file contains 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" | |
"math" | |
) | |
const float64MantissaMask = 0xFFFFFFFFFFFFF | |
const float64ExponentMask = 0x7FF0000000000000 | |
const float64SignMask = 0x8000000000000000 |
This file contains 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() { | |
gray(8) | |
} |
This file contains 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 roundUpToPow2(x uint64) uint64 { | |
x-- | |
x |= x >> 1 | |
x |= x >> 2 | |
x |= x >> 4 | |
x |= x >> 8 |
This file contains 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" | |
"sync" | |
"time" | |
) | |
type info struct { | |
step, thread uint64 |
This file contains 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" | |
"math" | |
) | |
// http://www.johndcook.com/blog/2015/10/06/number-of-digits-in-n/ | |
func digitsInFactorial(x int) int { | |
if x <= 0 { |
This file contains 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
import ( | |
"fmt" | |
) | |
func nand(x, y bool) bool { return !(x && y) } | |
func not(x bool) bool { return nand(x, x) } | |
func and(x, y bool) bool { return not(nand(x, y)) } | |
func or(x, y bool) bool { return nand(not(x), not(y)) } | |
func nor(x, y bool) bool { return not(or(x, y)) } | |
func xor(x, y bool) bool { return nand(nand(x, nand(x, y)), nand(nand(x, y), y)) } |
This file contains 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" | |
"math" | |
) | |
// Simpson's Rule for numerical integration of f from a to b using n steps | |
// Port of python code: http://stackoverflow.com/questions/16001157/simpsons-rule-in-python | |
func simpsons(f func(float64) float64, a, b float64, n int) float64 { |
OlderNewer