logoalt Hacker News

weinzierlyesterday at 3:55 PM5 repliesview on HN

Yes. For example in Rust it took a long time for floating point operations to be available at compile time and even now only a subset is. The reason is that a lot of energy and thought went into the issue of producing identical output (and what identical precisely means ) even when compilation is on a different processor than where the target runs.

As far as I know this is not a concern for Zig comptime.


Replies

dnauticstoday at 6:18 AM

Zig Comptime uses softfloat so it has architecture independent determinism.

And the zig core team is absolutely concerned with bitwise determinism in the compiled artifacts, iirc this is why they rejected the sloppy bun PR to the compiler.

show 1 reply
rvrbyesterday at 8:00 PM

there has been a ton of work on making comptime a pure and deterministic execution environment. I do not expect that work to stop. I don't know where you are getting the idea that it is not an important design consideration for the language.

to expand, if two different host platforms cross compiling to the same target platform have different results, I am almost certain that would be considered a compiler bug.

if you're pointing out that a runtime operation and a compile time operation might not agree, I'd be more interested in understanding when that would ever have any meaningful impact on anything. given the compilation is supposed to be deterministic, the difference can easily be addressed by comptime branching on target architecture in the rare case that it matters for your program.

show 2 replies
pjmlptoday at 5:49 AM

In C++ as well, constexpr math introduced in C++23 has similar concerns regarding floating point accuracy.

nvme0n1p1yesterday at 7:30 PM

What's your source for this? Comptime Zig code can do pointer casts and whatnot, all emulated as if run on the target bitness/endianness/etc. And any operations that are undefined on the target platform result in a compile error. I've never had an issue cross-compiling.

show 1 reply
chaz72yesterday at 5:22 PM

Now I see this response, I responded to the other comment.