ChanServ changed the topic of #zig to: zig programming language | https://ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
mixi has joined #zig
g_w1 has joined #zig
ur5us has joined #zig
ur5us_ has quit [Ping timeout: 260 seconds]
g_w1 has quit [Quit: Connection closed]
jmiven has joined #zig
<daurnimator> ifreund: the OS gives you them because you're talking to C :)
<ifreund> daurnimator: fair enough, someone should write an OS with a slice based syscall ABI :P
<daurnimator> ifreund: have you seen NT? :)
<ifreund> nope
<daurnimator> this is why NT paths can have null bytes in them
<ifreund> ah windows thing
<ifreund> Is that not written in C as well?
<daurnimator> it is. but they made all the syscalls have slice based ABIs
<daurnimator> where they screwed up was making them all UCS2 :/
<daurnimator> ifreund: https://docs.microsoft.com/en-us/windows/win32/api/subauth/ns-subauth-unicode_string <== most windows APIs that take strings (such as for path arguments) take a UNICODE_STRING
<ifreund> wonderful, an OS that cares about unicode :D
<daurnimator> What a pity it was invented in that breif period where we realised 256 characters was not enough; but still thought 65536 was enough
waffle_ethics has quit [Ping timeout: 264 seconds]
ur5us has quit [Ping timeout: 246 seconds]
knebulae has quit [Read error: Connection reset by peer]
knebulae has joined #zig
gazler_ has joined #zig
gazler has quit [Ping timeout: 265 seconds]
koakuma has quit [Quit: Leaving.]
ur5us has joined #zig
rabbipires has joined #zig
ky0ko has quit [Remote host closed the connection]
rowbee has quit [Ping timeout: 246 seconds]
sebonirc has quit [Ping timeout: 246 seconds]
adsr has quit [Ping timeout: 264 seconds]
rabbipires is now known as rowbee
ky0ko has joined #zig
sebonirc has joined #zig
philtor has quit [Ping timeout: 264 seconds]
adsr has joined #zig
livoreno has joined #zig
ur5us_ has joined #zig
ur5us has quit [Ping timeout: 260 seconds]
kameliya has quit [Quit: connection reset by purr]
kameliya has joined #zig
livoreno has quit [Ping timeout: 256 seconds]
kameliya has quit [Ping timeout: 256 seconds]
sebonirc has quit [Ping timeout: 256 seconds]
sebonirc has joined #zig
kameliya has joined #zig
pixelherodev has quit [K-Lined]
notzmv has joined #zig
xackus has joined #zig
xackus_ has quit [Ping timeout: 240 seconds]
nvmd has quit [Ping timeout: 246 seconds]
nvmd has joined #zig
pixelherodev has joined #zig
noam has joined #zig
pixelherodev has quit [Quit: ZNC 1.6.2 - http://znc.in]
noam is now known as pixelherodev
zmv has joined #zig
ur5us_ has quit [Ping timeout: 260 seconds]
Stephie has quit [Quit: Fuck this shit, I'm out!]
<mikdusan> oh i done fucked up something now
<mikdusan> ah nuked it. by mistake pushed to zig instead of fork.
waleee-cl has quit [Quit: Connection closed for inactivity]
Stephie has joined #zig
<mikdusan> (sorry for confusion. i pushed a PR branch by mistake and it's now removed. all good)
blueberrypie has quit [Quit: leaving]
blueberrypie has joined #zig
<mikdusan> would be sweet if we could have a slice+capacity type. the syntax would be tough. `buf[0.. .capacity]` or `buf[0.. :0 .capacity]` makes a slice with `.capacity` field
<daurnimator> mikdusan: you mean ArrayList?
cole-h has quit [Quit: Goodbye]
<daurnimator> (but with special syntax)
<mikdusan> my next comment wsa going to be "but maybe that's best left to std" and then just as I was saying "oh like ArrayList" you popped up :)
cole-h has joined #zig
* mikdusan replaces "upstream" url to read-only lol
sord937 has joined #zig
decentpenguin has quit [Read error: Connection reset by peer]
decentpenguin has joined #zig
slact has quit [Remote host closed the connection]
tnorth has joined #zig
osa1_ is now known as osa1
frett27_ has quit [Ping timeout: 272 seconds]
xackus has quit [Ping timeout: 260 seconds]
redj has quit [Ping timeout: 265 seconds]
redj_ has joined #zig
xackus has joined #zig
<mikdusan> did zig ever have .field access for error union payload/err ?
_whitelogger has joined #zig
inet56 has joined #zig
inet56 has left #zig [#zig]
midgard_ has quit [Ping timeout: 246 seconds]
hch has quit [Ping timeout: 256 seconds]
cow-orker has joined #zig
hch has joined #zig
xackus has quit [Quit: Leaving]
midgard has joined #zig
<mikdusan> this example is "no inline function call" and the closest CallOption seems to be .never_inline, yet it's not used in that example:
cole-h has quit [Ping timeout: 260 seconds]
hnOsmium0001 has quit [Quit: Connection closed for inactivity]
<tnorth> hey there. I'm trying to write the raw bytes of a []f32 variable A to a file via std.os.write(). It requires a []u8. I expected to be able to write const foo = std.mem.bytesAsSlice(u8, A), but it seems that this type of cast is not allowed. What would be the right way to do it?
<mikdusan> writeByte ?
<mikdusan> oh not in std.os :(
<mikdusan> see std.mem.toBytes()
<dutchie> or asBytes
<tnorth> sliceAsBytes() did it
<tnorth> Still discovering std functions...
xackus has joined #zig
<kbd> I can't figure out how to type this array concatenation: https://gist.github.com/kbd/a344a3202fbc3d51935e3821a7797dd4
<ikskuh> use { &a1, &a2 }
<ikskuh> you need to have a pointer to the array
<dutchie> what's the option to get zig to print the paths it's using to std library etc
<dutchie> oh, `zig env` there it is
nvmd has quit [Ping timeout: 256 seconds]
<kbd> ikskuh: thanks. That results in another compile error, but got me to: `var a3 = try std.mem.concat(A, []const u8, &[_][][]const u8{ &a1, &a2 });` which seems correct now.
<ikskuh> ah yeah
v0idifyy has joined #zig
v0idify has quit [Ping timeout: 268 seconds]
<daurnimator> kbd: you may want `const` rather than `var` too :)
<kbd> Yeah was just test code but ty, appreciate it.
koakuma has joined #zig
frett27_ has joined #zig
jokoon has joined #zig
<ifreund> anyone have code lying around to parse/format signed fixed point numbers without lossy conversion to floating point?
notzmv has quit [Read error: Connection reset by peer]
sord937 has quit [Ping timeout: 268 seconds]
sord937 has joined #zig
frett27_ has quit [Ping timeout: 246 seconds]
V has quit [Quit: No Ping reply in 180 seconds.]
osa1 has quit [Read error: Connection reset by peer]
osa1 has joined #zig
V has joined #zig
Miaourt has quit [Quit: Ping timeout (120 seconds)]
Miaourt has joined #zig
xyproto has quit [Ping timeout: 272 seconds]
jokoon has quit [*.net *.split]
adsr has quit [*.net *.split]
knebulae has quit [*.net *.split]
jmiven has quit [*.net *.split]
squeek502 has quit [*.net *.split]
mokafolio has quit [*.net *.split]
via has quit [*.net *.split]
jsb has quit [*.net *.split]
pjz has quit [*.net *.split]
Ziemas has quit [*.net *.split]
GrooveStomp has quit [*.net *.split]
semarie has quit [*.net *.split]
leon-p has quit [*.net *.split]
factormystic has quit [*.net *.split]
lemmi has quit [*.net *.split]
racoon has quit [*.net *.split]
johnLate has quit [*.net *.split]
jaredmm has quit [*.net *.split]
tsujp1 has quit [Ping timeout: 272 seconds]
tsujp1 has joined #zig
dom96 has quit [Ping timeout: 246 seconds]
jokoon has joined #zig
knebulae has joined #zig
adsr has joined #zig
squeek502 has joined #zig
jmiven has joined #zig
mokafolio has joined #zig
via has joined #zig
pjz has joined #zig
jsb has joined #zig
GrooveStomp has joined #zig
Ziemas has joined #zig
leon-p has joined #zig
factormystic has joined #zig
racoon has joined #zig
semarie has joined #zig
lemmi has joined #zig
jaredmm has joined #zig
johnLate has joined #zig
paulsmith has quit [Ping timeout: 246 seconds]
dom96 has joined #zig
ugla has quit [Ping timeout: 258 seconds]
siraben has quit [Ping timeout: 240 seconds]
pafmaf[m] has quit [Ping timeout: 240 seconds]
ziguana[m] has quit [Ping timeout: 244 seconds]
BaroqueLarouche has quit [Ping timeout: 244 seconds]
Nypsie[m] has quit [Ping timeout: 244 seconds]
bfredl has quit [Ping timeout: 244 seconds]
protheory8-new-m has quit [Ping timeout: 258 seconds]
Snektron has quit [Ping timeout: 258 seconds]
fengb has quit [Ping timeout: 258 seconds]
jaens[m] has quit [Ping timeout: 244 seconds]
mtiljeset[m] has quit [Ping timeout: 268 seconds]
Bastian[m] has quit [Ping timeout: 240 seconds]
ifreund_ has quit [Ping timeout: 258 seconds]
greeb has joined #zig
xyproto has joined #zig
ugla has joined #zig
mtiljeset[m] has joined #zig
jaens[m] has joined #zig
pafmaf[m] has joined #zig
ziguana[m] has joined #zig
pafmaf[m] has quit [Ping timeout: 246 seconds]
jaens[m] has quit [Ping timeout: 246 seconds]
ziguana[m] has quit [Ping timeout: 260 seconds]
mtiljeset[m] has quit [Ping timeout: 268 seconds]
ugla has quit [Ping timeout: 240 seconds]
xackus has quit [Read error: Connection reset by peer]
xackus_ has joined #zig
jeyr has joined #zig
protheory8-new-m has joined #zig
jeyr has quit [Client Quit]
Nypsie[m] has joined #zig
BaroqueLarouche has joined #zig
Snektron has joined #zig
siraben has joined #zig
nyaa8 has quit [Quit: byeee~]
Bastian[m] has joined #zig
fengb has joined #zig
Ashpool has joined #zig
ifreund_ has joined #zig
Ashpool has quit [Client Quit]
jaens[m] has joined #zig
ziguana[m] has joined #zig
mtiljeset[m] has joined #zig
zmv has quit [Read error: Connection reset by peer]
pafmaf[m] has joined #zig
ugla has joined #zig
heitzmann[m] has joined #zig
Akuli has joined #zig
datalus has quit [Quit: WeeChat 3.0]
<mikdusan> huh that explains it. $HOME/.cache/ now used for global cache on macos too
donniewest has joined #zig
notzmv has joined #zig
nvmd has joined #zig
xackus_ has quit [Ping timeout: 240 seconds]
jokoon has quit [Quit: Leaving]
blueberrypie6 has joined #zig
Miaourt0 has joined #zig
Yardanico has quit [Remote host closed the connection]
Miaourt has quit [Ping timeout: 256 seconds]
midgard has quit [Ping timeout: 256 seconds]
blueberrypie has quit [Ping timeout: 256 seconds]
blueberrypie6 is now known as blueberrypie
SimonNa has quit [Ping timeout: 256 seconds]
Miaourt0 is now known as Miaourt
SimonNa has joined #zig
Yardanico has joined #zig
jacob3 has joined #zig
jacob3 is now known as g_w1
tnorth has quit [Ping timeout: 264 seconds]
g_w1 is now known as g-w1
midgard has joined #zig
waleee-cl has joined #zig
notzmv has quit [Ping timeout: 264 seconds]
Ashpool has joined #zig
g-w1 has quit [Ping timeout: 246 seconds]
jacob3 has joined #zig
jacob3 is now known as g-w1
sord937 has quit [Quit: sord937]
<justin_smith> is there a good reference for the package rules? I'm used to being able to do multi segment packages (eg src/foo/bar.zig) but that leads to "import of file outside package path" when I go two levels back up
<fengb> You need to set the root to be src
<justin_smith> fengb: when I search the docs for that I get a bunch of TODO comments and some compiler output- where would I find out what this means?
<justin_smith> fengb: is this --main-pkg-path ?
<fengb> Yeah maybe. I’m not in front of my computer >_>
<justin_smith> fengb: yeah - that fixed it, found it by searching the output of "zig --help" for "root"
nvmd has quit [Ping timeout: 246 seconds]
<fengb> I normally use zig build which sets these cli args for me
nvmd has joined #zig
<justin_smith> yeah I prefer Makefile because it's more terse and I can mix CLI steps with zig stuff, but I guess that leaves some gotchas
<justin_smith> (there are many reasons that make is bad, but I've already spent the time learning how to use it properly...)
<fengb> We need translate-make 🙃
<justin_smith> of course I could use make AND build.zig, but up until now that seemed silly
<Nypsie[m]> Or only use build.zig
<justin_smith> Nypsie[m]: I haven't found a nice way to use external CLI tools in build.zig
frett27_ has joined #zig
cole-h has joined #zig
<Nypsie[m]> You can call external CLI tools from your build.zig file and have them depend on other steps, or even other steps depend on that step
<Nypsie[m]> I think you can call some command with `b.addSystemCommand()`
<justin_smith> Nypsie[m]: I had been using build.zig, but for this project that got extremely unweildy (it was advent of code, where for each day I added another target)
<justin_smith> Nypsie[m]: but it's likely this is because of my incompetence / ignorance rather than a problem with build.zig
<justin_smith> make was much easier for me
<Nypsie[m]> You could have that fully automated since you can just write some zig code that reads all directories/files and build some example for it.
<Nypsie[m]> Tbh, I don't blame you. docs regarding build.zig a big TODO
<Nypsie[m]> Was just mentioning it was possible, not trying to force you to use it fyi
<ifreund> justin_smith: you're 100% right that using external CLI tools from build.zig is not as frictionless as doing the same in make. It is totally possible though
<ifreund> see e.g. my scdoc invocation: https://github.com/ifreund/river/blob/master/build.zig
<ifreund> since you mentioned AoC, there's actually a temlate here as well: https://github.com/SpexGuy/Zig-AoC-Template/blob/main/build.zig
<justin_smith> ifreund: oh, that's clever - if I'd seen that before I was nearly done I totally would have used it
nvmd has quit [Ping timeout: 256 seconds]
nvmd has joined #zig
vmv has joined #zig
<vmv> Hello. I have one question. I am just wondering...how functional zig could be?
<justin_smith> vmv: having come from functional programming, it can do many of the individual idioms, but the lack of gc makes them much more verbose
<vmv> To be honest I am quite happy about the lack of gc. Do you have any examples of the possible functional way in Zig? :)
<justin_smith> vmv: I doubt my code examples are anything anyone should emulate
<justin_smith> (I'm still learning)
<ifreund> honestly I think trying to do functional-style programming in zig is going to be too high-friction for anything non-trivial
<ifreund> allthough that stack-capturing macro proposal would help a good deal
cole-h has quit [Quit: Goodbye]
cole-h has joined #zig
<ifreund> definitely better than C though :P
<semarie> #1717 "Make function definitions expressions" would help too for functional-style
<ifreund> oh certainly
<ifreund> though that's purely syntax aside from the function pointer related changes
<ifreund> wouldn't help with error/memory handling
<justin_smith> ifreund: actually, the pervasive usage of error union return values is also fp friendly (compared to try/catch or condition variables you need to remember to check)
<fengb> Except anon functions aren’t closures
<justin_smith> "lifting" from fn + state into a struct containing state plus a method is trivial, though tedious
<justin_smith> the classic object / closure duality
<justin_smith> (though I'm used to taking it in the other direction)
<fengb> Zig has neither objects nor closures 🙃
<justin_smith> fengb: but when I want an "object" I can use a struct with methods in it
<justin_smith> sorry, I am using "object" very loosely here
<fengb> Yeah I know, and I’m being a pedantic jerk
<justin_smith> like, as someone migrating here from clojure, I can take the code I'd normally write, and move everything in the let block into a struct type, add an "invoke" or whatever, and get the main features of an implicit closure (with a lot more lines of code)
<justin_smith> the harder part is reorganizing so my allocation lifespans make sense (the lack of gc part)
cole-h_ has joined #zig
cole-h has quit [Ping timeout: 256 seconds]
<vmv> For someone from Elixir/Rust world it could be too low. Can I pass function to a function in zig?
<justin_smith> vmv: yes, you can even pass types at compile time to make a new type
<vmv> Can I create a "pipeline" like in Ocaml or Elixir?
<justin_smith> vmv: and yes, it's very low level
<vmv> As low as Go? Hmm Go is a really strange case...some parts are really high level, some are so low. I am searching something which I know to compare.
<justin_smith> lower than go, since go uses gc
<Nypsie[m]> I wouldn't call Go a very low language tbh. Zig is definitely considered to be a lower language than Go.
<justin_smith> vmv: the design goal of zig is to be as low level as it can be, while also being simpler in design than legacy options
<vmv> I see. Can you give me some examples of a applications which would be perfect for Zig? As I can understand it will not be a potential "web" programming language with web frameworks?
<justin_smith> eg, being able to use the language at compile time instead of a macro system, code modules as structs
cole-h_ is now known as cole-h
<justin_smith> vmv: embedded applications, I hope to use it for DSP where getting the most out of your hardware is important
<justin_smith> systems programming in general
<ikskuh> vmv: pretty much anything is a good application for zig imho
<justin_smith> vmv: yeah, I'd use something much higher level for web programming, but I might use zig for a service in some bottleneck scenario
<ikskuh> desktop applications, web servers, system daemons, low latency trading software, bare metal applications (embedded or OS development)
<ikskuh> game programming
<ikskuh> justin_smith: i don't think we'll get Zig on proper DSPs soon
<justin_smith> ikskuh: I mean DSP as a software domain, not a type of hardware
<justin_smith> ikskuh: signal processing / generation / analysis stuff
<vmv> Hmm how about threads...is it possible to implement actor based system in Zig?
<ikskuh> justin_smith: ah, okay. yeah, then i agree
<ikskuh> actor based systems?
<justin_smith> vmv: there's a semi-experimental async system including sugar for resumable stack frames
<ikskuh> zig has both async-await semantics to express concurrency as well as OS threads for multithreading
<justin_smith> ikskuh: actor systems are an object oriented abstraction over multi threaded processes based on message passing coordination
<vmv> those are green threads/fibers on real threads?
<ikskuh> no
<ikskuh> async/await is manually managed coroutines
<ikskuh> there is no scheduling or anything
<ikskuh> and OS threads are OS threads
<vmv> I would not say that actors are object oriented.
<vmv> I see.
<ikskuh> i've skimmed over the wiki article
<justin_smith> vmv: they use internal state plus messages as their base, those are the "good parts" of OO
<ikskuh> yeah, you can do actor model programming
<ikskuh> use a thread safe queue/channel
<ikskuh> and threads
<vmv> Ok, my last question. Can I compile Zig to C? :) That part is unclear for me.
<ikskuh> not yet :D
<justin_smith> vmv: it's a replacement for c, you can translate c into zig
<vmv> If yes then I could use it in Erlang to make the number crunching faster
<ikskuh> you can use it in erlang already i think
<ikskuh> gimme a sec
<justin_smith> vmv: you can compile to an output that works with the c abi
<justin_smith> vmv: that's surely what erlang needs?
cole-h has quit [Quit: Goodbye]
<ikskuh> elixir FFI works exceptional with zig according to this talk
<vmv> It is Elixir so I could be more complicated to do it with pure Erlang.
<vmv> Based on what you have said I think that Zig would be perfect for blockchain :D
<ikskuh> oh no.
<vmv> oh yes...;)
<vmv> But seriously, why not ? I am not a huge fan ob blockchain but I have spend my last 3 years on bc projects.
<vmv> Safe, FAST, predictable
<vmv> Those are attributes which are quite important there. Take a look on the technologies which are popular there: Rust (It has solved problems of Go but also brings a couple of new one), Go (haha), Haskell (amazing, but lazy so hard to predict), OCaml (Threads...who need more then one ?!). Zig could be like a golden point of balance.
<vmv> Or maybe I am wrong. It has something interesting.
cole-h has joined #zig
cole-h has quit [Client Quit]
<justin_smith> vmv: while zig does borrow some nice features from eg. ml that those languages also use, it's probably more informative to compare zig to c or c++
<justin_smith> it's closer to being "c with modules and type inference" than it is to being "OCaml without gc but with threads" (both very loose comparisons)
slact has joined #zig
xackus_ has joined #zig
cole-h has joined #zig
<ifreund> I agree that zig would be a good language for blockchain code, though I think it's more generally a good language for anything that needs to be fast.
cole-h has quit [Client Quit]
<ifreund> s/fast/efficient/
ur5us_ has joined #zig
<justin_smith> or even more generally, things that require careful control of resources (including time, memory, disk space...)
cole-h has joined #zig
dongcarl has quit [Quit: The Lounge - https://thelounge.chat]
dongcarl has joined #zig
frett27_ has quit [Ping timeout: 272 seconds]
midgard_ has joined #zig
midgard has quit [Ping timeout: 256 seconds]
vpzom has joined #zig
<ifreund> that's what I meant by efficient :P
ur5us has joined #zig
sawzall has quit [Read error: Connection reset by peer]
ur5us_ has quit [Ping timeout: 246 seconds]
sawzall has joined #zig
hnOsmium0001 has joined #zig
leon-p has quit [Quit: leaving]
<mikdusan> i hate cmake
<ifreund> oh yes
<veltas> hmm
FireFox317 has joined #zig
<FireFox317> andrewrk, i'm trying to implement inferred blocks and i'm wondering if there is a downside to using the current `inferred_ptr` mechanism to determine the type of the block. See this gist: https://gist.github.com/FireFox317/21a0109030491b3a81fe579b0052fe40
marijnfs has joined #zig
<marijnfs> is there a hex-print in std?
<justin_smith> marijnfs: you can use {x} in place of {} inside std.debug.print
<andrewrk> FireFox317, taking a look
<justin_smith> marijnfs: there's a nice breakdown of the codes that work near the top of std.fmt
<marijnfs> justin_smith: sweet
<andrewrk> FireFox317, in this example it looks like the inferred mechanism is being used for the variables only, and the block type is being determined by a deref on `y` (which looks good)
<andrewrk> this ZIR looks good to me
<FireFox317> yes, I think that is correct. That also means that we can get rid of the `block_ptr` ResultLocation, because the type of the block is actually determined through the `inferred_ptr` Resultlocation. do you think that make sense?
Akuli has quit [Quit: Leaving]
<FireFox317> i also updated the gist to include the ZIR of the more complex example
<FireFox317> andrewrk, your statement was incorrect. The inferred mechanism is also being used for the `const x`. Before every break there is now a `store_to_inferred_ptr` that points to the `alloc_inferred` of the `const x`. And the `resolve_inferred_alloc` after the block then does the `resolvePeerTypes`. Does that make sense?
<andrewrk> FireFox317, those instructions have to do with the fact that there is a variable declaration though, not the fact that there is a block, right?
<andrewrk> for example what if the block was a parameter to a function?
<FireFox317> `const x = <whatever>` uses the `inferred_ptr` mechanism. and in this case <whatever> is a block
<FireFox317> andrewrk, i updated the simple example. I think it is clearer now
<andrewrk> looking
<andrewrk> can you state the question again?
<andrewrk> this ZIR all looks good - I just don't understand how it relates to the question
<FireFox317> is it okay to reuse the inferred_ptr mechanism to determine the type of the block? so currently there is a `block_ptr` resultLocation, which is suppose to handle that case. But i figured out that i can actually reuse the `inferred_ptr` mechanism to determine the type of the block, which makes the `block_ptr` useless
<FireFox317> I was wondering if there is some case where we actually cannot determine the type of the block in this way.
<andrewrk> let's try to come up with a motivating example that would help answer this question. I'm poking around locally - first I'm going to look at ZIR for a labeled block used as a function call parameter
<waleee-cl> vmv: if actors are necessary but you don't want to do erlang/elixir ... have you considered pony(lang)?
<vmv> waleee-cl: Sure, Pony is amazing. I am just a little bit afraid that the community and progress are a little bit slower then 2 years ago in Pony (or it is only my feeling) :)
<fengb> I have unidirectional actors over threads in Zig but it’s not pretty
Daimanta has joined #zig
<Daimanta> Hi!
<fengb> Was actually planning to port to async instead, but that’s been buggy
<Daimanta> I have a question about Zig because I ran into some strange code
<Daimanta> Well, the code was not strange but the results were
<ifreund> FireFox317: haven't looked in depth, but does this handle breaking the block with an error and a value in different places causing the block type to be inferred as an error union?
<ifreund> (this doesn't work in stage1, but I'm of the opinion that it should)
<ifreund> Daimanta: do share
<FireFox317> andrewrk, yep i also looked at that case and that all works out when the type of the function call parameter is known.
<Daimanta> I was making a small Zig math library and was comparing it to some std math code
<FireFox317> I then thought what if the type of the function paramater is `anytype`? But then I couldnt try that because stage2 doesnt support that yet.
<Daimanta> I compared my code to the cos function in std.math to see what the precision was.
<Daimanta> When I entered two consts with f32 and f64 values I found results that differ too much in my opinion
<Daimanta> const a: f32 = 89433.0;
<Daimanta>     const b: f64 = 89433.0;
<Daimanta>     try std.io.getStdOut().writer().print("{}\n", .{math.cos(a)});
<Daimanta>     try std.io.getStdOut().writer().print("{}\n", .{math.cos(b)});
<Daimanta> So, here's the code.
gpanders has quit [Remote host closed the connection]
<FireFox317> ifreund, hmm that is a good usecase
<ifreund> FireFox317: context: https://github.com/ziglang/zig/issues/5610
<Daimanta> The results should be very similar in my opinion, but thet are not
<Daimanta> The results I got were as follows:
<Daimanta> -2.81683772e-01
<Daimanta> -2.848654575667813e-01
<andrewrk> FireFox317, if we can delete the block_ptr result loc, that's great, I'm just trying to come up with examples to make sure :)
<andrewrk> is this blocking something?
<FireFox317> andrewrk, yes indeed, that is what i thought too. I was also thinking of examples
<FireFox317> andrewrk, nah just improving stage2 :)
<Gliptic> is there any way to do recursion in async contexts? I realize you have to break the cycle somehow, but can't figure out how exactly
<Daimanta> That is a difference of more than 1%, which should not happen
<andrewrk> I see - well I think we can leave it for now, and once we get basic test coverage of all the language we can remove it. maybe earlier if it becomes a blocker for something
<andrewrk> right now it serves as a "TODO" if you run into it
<andrewrk> or maybe there's something I'm not understanding
<andrewrk> Gliptic, you have to heap allocate the frame of the function you want to call
<andrewrk> then `ptr.* = async foo();`
<FireFox317> andrewrk, remove 'it'? what?
<Gliptic> andrewrk: thanks, I'll try that, but it was complaining that the function wasn't analyzed if I did just async foo()
<andrewrk> FireFox317, ah I thought you were suggesting to remove ResultLoc.block_ptr
<FireFox317> andrewrk, okay yeah i see what you mean now. I will PR this stuff and then you can have another look at it :)
<andrewrk> sounds good!
vmv has quit [Remote host closed the connection]
<ifreund> Daimanta: probably an accumulation of rounding errors in the f32 version?
<Daimanta> I'd wager that such a thing would be the case
<Daimanta> In any case, it's not good
<Daimanta> the input values are "small" which should not incur floating rounding issues
<ifreund> Do you have an example of anything that has a more accurate 32 bit float cosine algorithm?
<Daimanta> I'm checking alternative calculations right now
nvmd has quit [Quit: Later nerds.]
<Gliptic> andrewrk: ah, thanks, it works
xackus_ has quit [Ping timeout: 256 seconds]
<andrewrk> np
<andrewrk> Gliptic, this stuff is still experimental; you may run into issues
<Daimanta> I checked the answer on other tools and the answer looks way off
<ifreund> what tools?
<Daimanta> Wolfram alpha and a random open source calculator(speed crunch)
<ifreund> are you sure they do the calculation in 32bit IEEE floats?
<ifreund> wolfram alpha certainly doesn't
<Gliptic> I realize that
<ifreund> it uses arbitrary precision
<Daimanta> Bit return a value like  -0,284865
<Daimanta> *Both
<Daimanta> So either I'm missing something or the cosine falls apart at some values
<ifreund> Daimanta: I think everything you're using that gives you a more accurate value is using more precision than an f32
<ifreund> there's a reason c's math.h uses doubles for everything
<Daimanta> That seems unlikely, since f64 have the same issue
<ifreund> no?
<Daimanta> Well, the answer still seems wrong
<Daimanta> oh, wait
<Daimanta> No it isnt
<Daimanta> You're right
<Daimanta> scientific notation caught me
<Daimanta> so yeah, the f32 somehow degenerates due to some unknown reason
<ifreund> s/unknown reason/floating point rounding errors/
<ifreund> which are a lot more apparent when you have less precision
<Daimanta> I do get that, but since the cos function maps the reals to [-1,-1] I'd expect a stable answer for these values as well.
<Daimanta> I'll check how c deals with this and I'll compare the results.
<ifreund> Daimanta: libc doesn't offer a cos() that takes a float
<Daimanta> ah, I see
<fengb> Are f32s deprecated or something? Seems like nothing supports it
<ifreund> 23:53 <ifreund> there's a reason c's math.h uses doubles for everything
<fengb> Yeah I’m just surprised a 1989 spec uses doubles :P
<ifreund> I'm assuming because float would cause the rather atrocious rounding issues Daimanta has pointed out
<andrewrk> FireFox317, related: https://clbin.com/G8h1W
<andrewrk> uh let me fix that syntax
<Daimanta> Well, the many multiplications probably exacerbate the rounding error
<andrewrk> FireFox317, fixed: https://clbin.com/ahyjk
<andrewrk> damn it, pretend it says "const result" instead of "const x"
donniewest has quit [Quit: WeeChat 3.0]
<FireFox317> andrewrk, i would expect option 1 here i think
<Daimanta> Who developed the math lib anyway? I'm wondering what algorithm he used.
<andrewrk> tiehuis did most of the work, using a combination of musl and go
<andrewrk> musl semi-recently improved all their math, and I think we should refresh all the math funcs with musl and make sure we pick up the improvements
<Daimanta> It's really nice that Zig offers a real choice in datatypes in/output but stuff like this rounding error scares me a bit so I at least know to use 64bit datatypes right now
<Daimanta> Thanks for the information anyway, I'm off to bed now :)
<marijnfs> i want to write some 'dynamic' serialization for a struct, like any struct gets serialized in memory, a [4]u8 also, a []u8 needs a length to be stored
<marijnfs> how would I go about doing that?
Daimanta has quit [Quit: Ping timeout (120 seconds)]
<kameliya> marijnfs: can you clarify what you are needing to do exactly?
<g-w1> you may want to checkout this for inspiration https://github.com/ziglang/std-lib-orphanage/blob/master/std/serialization.zig
LanceThePants has joined #zig
koakuma has quit [Ping timeout: 256 seconds]
sawzall has quit [Read error: Connection reset by peer]
viashimo has joined #zig