Not relevant anymore.
The zig team is all for improving the experience with maths, but they donāt want to sacrifice clarity in the process.
It is a balance they are actively working on, at least the theory if not implementing it.
This should address a large part of the issues
for the float side
this thread had some ideas that andrew liked, aswell as some of his ideas.
Nope, an api will either have a technical maximum that they will be able to more accurately encode into types, currently they need an error if their maximum doesnāt happen to be log2.
Or the more likely case is they will be generic over the type.
Also, ranged integers will be able to coerce to other ranges if the other range fully encompasses the original range, e.g. 0 to 10 can coerce to -50 to 50.
This is such a small issue, but I would prefer the more verbose names to highlight the distinction, also for the visually impaired; r and f are quite similar.
Me too :D!
In all seriousness, I canāt see any reason an API will take a range that does not reflect the min/max they support. Such things the caller needs to deal with already.
If an API did use a dishonest range, then itās just bad code, entirely the fault of who wrote the API.
Feel free to prove me wrong :D.
Huh, thereās something I havenāt realized before!
My knee jerk reaction was to say something like
Well, you canāt represent every
u64losslessly asf64, so it would be odd ifu64was implicitly casted tof64. You could imagine iteration syntax likefor (0..10.0) |f|which would iterate floats, but thatās also a can of worms, because, for sufficiently large float numbers,a + 1.0 == a.
But then I realized that I can think about i * 1.5 not as implicitly converting i to f64, but rather as multiplying a floating point number by an integer. This seems like a good shift of perspective? Converting u64 to f64 is lossy, so itās good that we donāt do that. But multiplying f64 by u64 can actually be done precisely, because the loos of precision is already encoded in f64.
It is a bit like
var a: u64 = 10;
var b: i64 = 9;
const less: bool = a < b;
Although u64 and i64 represent different subsets of numbers, and you canāt losslessly convert one into another, it still is logically valid to ask which number is larger.
So, thanks, I think I am now in favor of allowing mixed floating/integer arithmetics (while still disallowing implicit coercions) based on fundamentals. Though, I havenāt written any numeric code in Zig, so I donāt have āin practiceā opinion here.
I do think that if youāre capturing a for loop with a comptime-known range, the result type should be comptime_int.
I think the idea is that it might feel like a rug-pull if you switch to a runtime-known range and suddenly it doesnāt coerce as well as it used to, but I personally feel like Zig programmers are mature enough to recognise why this happened.
That would essentially be an inferred inline which defeats the purpose of explicitly not using inline to let the optimiser decide.
Though the optimiser could turn it back into a loop if it thinks itās better.
IDK how well it would do in that regard, re-rolling a loop doesnāt seem like a high priority to put effort into making the optimiser good at it.
This is such a small issue, but I would prefer the more verbose names to highlight the distinction, also for the visually impaired; r and f are quite similar.
Iām not sure I get exactly what you mean here? Perhaps I misunderstood you/am not the visually impaired group youāre referring to (Iām totally blind and Iām sure lots of low-vision people use Zig, maybe itās a visual thing), but as a screen reader user, f64, f32, f16 all having the same letter makes more sense than r for some of them.
I think you misunderstand, the ārā isnāt arbitrary, there are big differences between a floating point number and a ārealā number.
See this link for more details https://github.com/ziglang/zig/issues/23173
I was stating that I would prefer the names from the proposal: real32 and float32 over r32 and f32. Because visually, the longer names are more distinct. On further thought, I also think the longer names have more distinct sounds, though your opinion would be more valid here.
I shouldnāt be talking on behalf of a group I am not in. If there are any visually impaired (not totally blind) on here, then they should share their opinion.
It is just something that comes to mind as I heard some talk about how their impairment and programming languages interact.
But even people who arenāt visually impaired, I think, would have a harder time distinguishing r32 and f32 at a glance compared to the longer names.
Ooh okay, sorry, what you said makes much more sense now. I agree with you, Iād also prefer real32/real64 as a fully blind screen reader user ![]()
Adding for (0..10) |i: i16| to the language would be really useful.
I would definitely take advantage of that, and canāt see disadvantages; could somebody highlight any disadvantages (perhaps other than the āitās just unnecessary sugarā types, which are easily anticipated)?
A slightly more constructive post: Here is the zig issue (not sure if it will survive?) where Andrew posts that this will not get fixed.
This might reopen once the ranged integers make their appearance though, we could loop through a ranged integer.
