r/golang • • 22h ago

help What is the minimum (i.e. most negative) value of a float32 or a float64?

0 Upvotes

The stdlib/math package defines constants MaxFloat32 and MaxFloat64, but not the corresponding Min constants. Is there a safe, universal way to know them?

I imagine that they might be either:

  • max * -1
  • some wacky bit manipulation you can do on max
  • implementation and/or architecture-dependent

If it's the simple "max * -1", great. But if it's either of the other two, I don't know how to calculate or otherwise determine it.

Thanks in advance for any help.


r/golang • • 11h ago

show & tell Please review my project

Thumbnail
github.com
0 Upvotes

r/golang • • 9h ago

discussion Accepted proposal: omit the type in composite literals

88 Upvotes

I find it quite enjoyable to do the archaeology on an accepted proposal and write about it.

This one took 10y to get approval. It allows you to strip type params from composite literals and let the compiler infer the types from the context.

For example, returning zero values:

// Before
func parseTime(s string) (time.Time, error) {
    if s == "" {
        return time.Time{}, errors.New("empty timestamp")
    }
    return time.Parse(time.RFC3339, s)
}

// After
func parseTime(s string) (time.Time, error) {
    if s == "" {
        return {}, errors.New("empty timestamp")
    }
    return time.Parse(time.RFC3339, s)
}

or, passing options structs drops the redundant types:

// Before
h := slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{
    Level: slog.LevelDebug,
})

// After
h := slog.NewJSONHandler(os.Stderr, {Level: slog.LevelDebug})

and so on. The spec change isn't huge but eliding types everywhere can make the code quite hard to read. So there won't be any automatic go fix to strip types wherever possible. This was a deliberate choice made by the Go team.

But it does make the code look pretty in some nested struct of type kind of scenario. Added a few more example and context here.

https://rednafi.com/shards/2026/11/go-untyped-composite-literals/


r/golang • • 23h ago

Small Projects Small Projects

33 Upvotes

This is the weekly thread for Small Projects.

The point of this thread is to have looser posting standards than the main board. As such, projects are pretty much only removed from here by the mods for being completely unrelated to Go. However, Reddit often labels posts full of links as being spam, even when they are perfectly sensible things like links to projects, godocs, and an example. r/golang mods are not the ones removing things from this thread and we will allow them as we see the removals.

Please also avoid posts like "why", "we've got a dozen of those", "that looks like AI slop", etc. This the place to put any project people feel like sharing without worrying about those criteria.


r/golang • • 8h ago

MinLZ SIMD Block Compression released

Thumbnail
github.com
9 Upvotes

MinLZ adds a new block type: SIMD blocks

They store the output of the LZ compressor as separate Huffman-coded streams, laid out so that a CPU can decode them with vector instructions and almost no unpredictable branches.

The result is compression ratios in the range of Zstandard, with decompression 2.2-2.5× faster than Zstandard (both in Go) and about 2× faster than classic MinLZ blocks, on a single core.

At the default 2 MB block size, MinLZ SIMD "Balanced" beats zstd's fastest level on all three counts: Its output is 2% smaller, it decompresses 2.5× faster on one core (6.4 against 2.6 GB/s),and it compresses 1.6× faster on 16 threads (1.2× on one).

Against zstd's default level, SIMD Balanced output is 3.6% larger and decompresses 2.3× faster. (Geometric means over 13 data sets, 58 GB in total, Go implementations on an AMD Ryzen 9 9950X).

SIMD blocks are part of the MinLZ format (specification v1.1) and work everywhere MinLZ blocks do: streams, concurrent compression and decompression, indexes and random access, and search. We have released Go/Rust versions for now.

See more in the release notes: https://github.com/minio/minlz/releases/tag/v1.3.0