Last active
September 8, 2024 18:20
-
-
Save iriswebb/086e841fe8cb0ad4d3eebc99c38b91a4 to your computer and use it in GitHub Desktop.
Print the bounds of the epoch at various resolution and (signed) integer width
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" | |
| import "math" | |
| import "time" | |
| func main() { | |
| tz, err := time.LoadLocation("UTC") | |
| if err != nil { // Always check errors even if they should not happen. | |
| panic(err) | |
| } | |
| a := [4]int64{1<<23, 1<<31, 1<<52, math.MaxInt64}; | |
| fmt.Println("Type/Resolution, float, int, double, long/x87 long double"); | |
| fmt.Print("Width"); | |
| for x := 0; x < len(a); x++ { | |
| fmt.Print(", "); | |
| fmt.Print(math.Log2((float64)(a[x]))); | |
| } | |
| fmt.Print("\n"); | |
| fmt.Print("1 ns"); | |
| for x := 0; x < len(a); x++ { | |
| fmt.Print(", "); | |
| fmt.Print(time.Unix(0, a[x]).In(tz).Format("2006-01-02T15:04")); | |
| } | |
| fmt.Print("\n"); | |
| fmt.Print("-1 ns"); | |
| for x := 0; x < len(a); x++ { | |
| fmt.Print(", "); | |
| fmt.Print(time.Unix(0, -a[x]).In(tz).Format("2006-01-02T15:04")); | |
| } | |
| fmt.Print("\n"); | |
| fmt.Print("10 ns"); | |
| for x := 0; x < len(a); x++ { | |
| fmt.Print(", "); | |
| fmt.Print(time.UnixMicro(a[x]/100).In(tz).Format("2006-01-02T15:04")); | |
| } | |
| fmt.Print("\n"); | |
| fmt.Print("-10 ns"); | |
| for x := 0; x < len(a); x++ { | |
| fmt.Print(", "); | |
| fmt.Print(time.UnixMicro(-(a[x]/100)).In(tz).Format("2006-01-02T15:04")); | |
| } | |
| fmt.Print("\n"); | |
| fmt.Print("1 us"); | |
| for x := 0; x < len(a); x++ { | |
| fmt.Print(", "); | |
| fmt.Print(time.UnixMicro(a[x]).In(tz).Format("2006-01-02T15:04")); | |
| } | |
| fmt.Print("\n"); | |
| fmt.Print("-1 us"); | |
| for x := 0; x < len(a); x++ { | |
| fmt.Print(", "); | |
| fmt.Print(time.UnixMicro(-a[x]).In(tz).Format("2006-01-02T15:04")); | |
| } | |
| fmt.Print("\n"); | |
| fmt.Print("1 ms"); | |
| for x := 0; x < len(a); x++ { | |
| fmt.Print(", "); | |
| fmt.Print(time.UnixMilli(a[x]).In(tz).Format("2006-01-02T15:04")); | |
| } | |
| fmt.Print("\n"); | |
| fmt.Print("-1 ms"); | |
| for x := 0; x < len(a); x++ { | |
| fmt.Print(", "); | |
| fmt.Print(time.UnixMilli(-a[x]).In(tz).Format("2006-01-02T15:04")); | |
| } | |
| fmt.Print("\n"); | |
| fmt.Print("1 s"); | |
| for x := 0; x < len(a); x++ { | |
| fmt.Print(", "); | |
| fmt.Print(time.Unix(a[x], 0).In(tz).Format("2006-01-02T15:04")); | |
| } | |
| fmt.Print("\n"); | |
| fmt.Print("-1 s"); | |
| for x := 0; x < len(a); x++ { | |
| fmt.Print(", "); | |
| fmt.Print(time.Unix(-a[x], 0).In(tz).Format("2006-01-02T15:04")); | |
| } | |
| fmt.Print("\n"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment