Leonidas changed the topic of #ocaml to: Discussion about the OCaml programming language | http://www.ocaml.org | OCaml 5.1.1 released: https://ocaml.org/releases/5.1.1 | Try OCaml in your browser: https://try.ocamlpro.com | Public channel logs at https://libera.irclog.whitequark.org/ocaml/
chiselfuse has quit [Remote host closed the connection]
chiselfuse has joined #ocaml
<discocaml> <cavemon.dev> how do you print a `Uchar.t` to `string`?
<discocaml> <limp.biskit> magic.
<discocaml> <struktured> Uchar.to_char is one path to victory, not sure if there is something more direct though
<discocaml> <cavemon.dev> first thing i tried, it raises this
<discocaml> <cavemon.dev>
<discocaml> <cavemon.dev> ```
<discocaml> <cavemon.dev> Uncaught exception:
<discocaml> <cavemon.dev>
<discocaml> <cavemon.dev> (Invalid_argument "U+4E3B is not a latin1 character")
<discocaml> <cavemon.dev> ```
<discocaml> <cavemon.dev> I'm using Notty to read key inputs
jabuxas has quit [Quit: oops :p]
<discocaml> <struktured> Maybe try Uchar.to_scalar ?
<discocaml> <cavemon.dev> ```
<discocaml> <cavemon.dev> let txt = String.make 1 @@ Char.chr @@ Base.Uchar.to_scalar u in
<discocaml> <cavemon.dev> ```
<discocaml> <cavemon.dev>
<discocaml> <cavemon.dev> ```
<discocaml> <cavemon.dev> Uncaught exception:
<discocaml> <cavemon.dev>
<discocaml> <cavemon.dev> (Invalid_argument Char.chr)
<discocaml> <cavemon.dev> ```
<discocaml> <struktured> Well th exn is because it's outside the range of a character, so that's to be expected
<discocaml> <cavemon.dev> how do i get a string from a uchar using Uchar.to_scalar
troydm has quit [Ping timeout: 268 seconds]
<discocaml> <deepspacejohn> You need to make a buffer first and append the uchar https://ocaml.org/manual/5.2/api/Buffer.html#1_Appending
<discocaml> <deepspacejohn> Then get the string from the buffer
<discocaml> <cavemon.dev> thanks
<discocaml> <darrenldl> anadon: if you don't mind dependency on angstrom, that would be what I would do
waleee has quit [Ping timeout: 268 seconds]
<discocaml> <barconstruction> I am having a really weird bug which lives somewhere close to the interface between OCaml and C. Is there anything that could cause a float to have a representation that C considers valid, but OCaml thinks is nan
<dh`> no
<dh`> most likely you are looking at the wrong bits
<discocaml> <barconstruction> would that be like a little endian/big endian issue?
<companion_cube> nan is valid
<companion_cube> but yeah, might be endianess
<discocaml> <barconstruction> What is -nan
<discocaml> <barconstruction> Like what does that mean?
<discocaml> <barconstruction> How do I tell if a number is equal to -nan?
<discocaml> <barconstruction>
<discocaml> <barconstruction> I did printf("%f",x) in the C program and it seems to have printed -nan.
<companion_cube> equality on nan makes little sense
<companion_cube> however: $ Float.classify_float ((-0.)/.0.);;
<companion_cube> - : fpclass = Float.FP_nan
<discocaml> <barconstruction> I'm getting a value in C such that
<discocaml> <barconstruction> - x !=x is false
<discocaml> <barconstruction> - printing it to the screen shows -nan
<discocaml> <barconstruction> - returning it to an OCaml program gives Float.classify_float x= Float.FP_nan
<discocaml> <barconstruction> - isnan(x) is false
<discocaml> <barconstruction>
<discocaml> <barconstruction> How can I come up with a test in C that would make this consistent
<companion_cube> all comparisons to nan are false
<companion_cube> in C I'm not entirely sure. In OCaml you can use Int64.bits_of_float and use that
<discocaml> <barconstruction> oh, it's not normal.
<discocaml> <barconstruction> isnormal(x) is false.
<companion_cube> `isnan()` exists! woo
<discocaml> <barconstruction> yeah, that is bullet point 4 above
<companion_cube> wut wut
<companion_cube> turn into int64, hex that shit, and use https://float.exposed/
<discocaml> <barconstruction> ```c
<discocaml> <barconstruction> assert (x == x);
<discocaml> <barconstruction> assert (~(isnan(x)));
<discocaml> <barconstruction> assert (~(isnormal(x)));
<discocaml> <barconstruction> ```
<discocaml> <barconstruction>
<discocaml> <barconstruction> Then I call `caml_copy_double` to return the result, and Float.classify_float gives nan
<companion_cube> what does fpclassify return?
<discocaml> <barconstruction> Here is the bitstring
<discocaml> <barconstruction> `0xFFF8000000000000`
<discocaml> <barconstruction> `fpclassify(x) == FP_NORMAL`
<companion_cube> very strange
<companion_cube> works for me, isnan() is true
<dh`> yes, that's a NaN
<discocaml> <barconstruction> Yes, it works for me too, ok. (That is, if I just write it as a standalone C program.)
<discocaml> <barconstruction>
<discocaml> <barconstruction> ```
<discocaml> <barconstruction> x=-nan
<discocaml> <barconstruction> is nan: 1
<discocaml> <barconstruction> is normal: 0
<discocaml> <barconstruction> fpclassify is nan: 1
<discocaml> <barconstruction> fpclassify is normal: 0
<discocaml> <barconstruction> ```
<discocaml> <barconstruction>
<discocaml> <barconstruction> This is all what we expect, I guess. But I'm getting a different answer in the context of this C library code that's being called from my OCaml program.
<dh`> still seems most likely to me that you're getting the wrong bits
<discocaml> <barconstruction> Sorry, I don't really know what you mean. I asked you if you meant endianness.
<dh`> it's not endianness, 0x0000000000001fff is also highly unlikely to be the number you're looking for (it's a subnormal/denormal)
<dh`> what I mean is: you are copying the wrong bits somehow
<dh`> though maybe not, the value you've got there is not an arbitrary pile of junk that happens to decode as NaN
<dh`> except for being negative it's the default NaN you'd likely get from a meaningless operation
<discocaml> <barconstruction> does anyone have Owl installed and want to try and reproduce this so I can see if it's just me
<discocaml> <barconstruction> the steps to reproduce are:
<discocaml> <barconstruction> 1. install owl
<discocaml> <barconstruction> 2. Open utop, require and open Owl, and #use this file https://github.com/owlbarn/owl/blob/main/src/owl/stats/owl_stats_dist.ml
<discocaml> <barconstruction> 3. run `gamma_isf 0.292000000000000037 ~shape:0.9 ~scale:1.`
<discocaml> <barconstruction> i'm going to bed tho it's late
Serpent7776 has joined #ocaml
_whitelogger has quit [Ping timeout: 260 seconds]
_whitelogger has joined #ocaml
GreaseMonkey has quit [Remote host closed the connection]
greaser|q has joined #ocaml
trillion_exabyte has quit [Ping timeout: 268 seconds]
trillion_exabyte has joined #ocaml
jutty has joined #ocaml
<vb> mpc update
<vb> oups. wrong window.
bartholin has joined #ocaml
YuGiOhJCJ has quit [Quit: YuGiOhJCJ]
chiselfuse has quit [Remote host closed the connection]
chiselfuse has joined #ocaml
troydm has joined #ocaml
wingsorc has quit [Ping timeout: 240 seconds]
chiselfuse has quit [Remote host closed the connection]
chiselfuse has joined #ocaml
chiselfuse has quit [Remote host closed the connection]
chiselfuse has joined #ocaml
troydm has quit [Quit: What is Hope? That all of your wishes and all of your dreams come true? To turn back time because things were not supposed to happen like that (C) Rau Le Creuset]
troydm has joined #ocaml
troydm has quit [Quit: What is Hope? That all of your wishes and all of your dreams come true? To turn back time because things were not supposed to happen like that (C) Rau Le Creuset]
troydm has joined #ocaml
troydm has quit [Quit: What is Hope? That all of your wishes and all of your dreams come true? To turn back time because things were not supposed to happen like that (C) Rau Le Creuset]
troydm has joined #ocaml
troydm has quit [Quit: What is Hope? That all of your wishes and all of your dreams come true? To turn back time because things were not supposed to happen like that (C) Rau Le Creuset]
troydm has joined #ocaml
troydm has quit [Client Quit]
troydm has joined #ocaml
troydm has quit [Quit: What is Hope? That all of your wishes and all of your dreams come true? To turn back time because things were not supposed to happen like that (C) Rau Le Creuset]
troydm has joined #ocaml
torretto has quit [Ping timeout: 260 seconds]
torretto has joined #ocaml
<discocaml> <barconstruction> This was very silly code. I forgot tilde denoted bitwise complement. I have not used C in a long time. I will have to rerun this later. But I think it is
myrkraverk_ has joined #ocaml
myrkraverk has quit [Ping timeout: 240 seconds]
myrkraverk has joined #ocaml
myrkraverk_ has quit [Ping timeout: 240 seconds]
<companion_cube> Oh no I should have seen, indeed
<companion_cube> It's "!" for negation of course :/
myrkraverk_ has joined #ocaml
myrkraverk has quit [Ping timeout: 240 seconds]
myrkraverk_ has quit [Read error: Connection reset by peer]
myrkraverk__ has joined #ocaml
myrkraverk__ has quit [Read error: Connection reset by peer]
myrkraverk__ has joined #ocaml
myrkraverk_ has joined #ocaml
myrkraverk__ has quit [Ping timeout: 268 seconds]
myrkraverk_ has quit [Remote host closed the connection]
myrkraverk_ has joined #ocaml
myrkraverk_ has quit [Ping timeout: 272 seconds]
<discocaml> <barconstruction> I tried it on another machine and couldn't reproduce the error so it might be something specific to my configuration.
<discocaml> <barconstruction> The function gives the correct answer.
<discocaml> <barconstruction> Don't worry, I asked on stack exchange and got three comments and two answers explaining the difference between bitwise negation and logical negation. (I understand the difference I just work at a place that uses Python)
<discocaml> <limp.biskit> is using bool to indicate success a bad pattern
<discocaml> <octachron> A possible inconvenient is that it is relatively easy to ignore the returned bool (compared to option/result/exceptions).
waleee has joined #ocaml
<discocaml> <lukstafi> There's some language support: `assert`. When using `ignore` remember to `ignore (... : bool)`.
<companion_cube> yes!!
<discocaml> <limp.biskit> companion_cube: compared to (unit, unit) Result?
<discocaml> <limp.biskit> this is adding data to a mutable structure
<companion_cube> no I'm saying, ignore should always go with a cast
<discocaml> <limp.biskit> ohh
<discocaml> <limp.biskit> in this context ignoring it would be an error anyway, as a false is supposed to indicate to stop pushing or generating data
<discocaml> <lukstafi> Raise an effect and resize the structure in the handler 😅
jutty has quit [Ping timeout: 252 seconds]
jutty has joined #ocaml
<companion_cube> another day, another moment of sadness at stdlib's IO channels
jutty has quit [Ping timeout: 268 seconds]
jutty has joined #ocaml
jutty has quit [Quit: jutty]
jutty has joined #ocaml
trillion_exabyte has quit [Ping timeout: 264 seconds]
trillion_exabyte has joined #ocaml
jutty has quit [Quit: jutty]
troydm has quit [Ping timeout: 260 seconds]
waleee has quit [Ping timeout: 264 seconds]
Serpent7776 has quit [Read error: Connection reset by peer]
Serpent7776 has joined #ocaml
<discocaml> <limp.biskit> another moment of sadness at stdlib in general
<dh`> <limp.biskit> is using bool to indicate success a bad pattern
<dh`> yes: does true mean "yes, it succeeded" or "yes, it failed"?
<dh`> :-|
<dh`> it can reasonably be either way, therefore it tends to create problems eventually
<discocaml> <limp.biskit> dh`: what would the alternatives be for a function with no meaningful return value though?
gzar has joined #ocaml
<dh`> there's always (unit, unit) Result.t
<dh`> or unit option
<companion_cube> [`Ok | `Ohno]
jutty has joined #ocaml
<discocaml> <Kali> i don't think using bool is a bad pattern if the function is named appropriately and there truly is nothing to return
<companion_cube> yeah sometimes it's clear enough
<discocaml> <deepspacejohn> I think it depends on what "success" means
Tuplanolla has joined #ocaml
<discocaml> <Kali> hence appropriate name
<discocaml> <limp.biskit> i've seen other io stuff implement similar patterns, so im probably fine
<discocaml> <limp.biskit> as far as user expectation
Serpent7776 has quit [Ping timeout: 264 seconds]
gentauro has quit [Read error: Connection reset by peer]
<discocaml> <contextfreebeer> I don't like bool return tbh, if you really want to use the return value for selection you can do `Option.is_some` or `Result.is_ok` etc. that seems cleaner to me
gentauro has joined #ocaml
<discocaml> <deepspacejohn> I guess it also depends on what failure means. if it's a programmer error then maybe raise an exception or return `Error "error message"`
Serpent7776 has joined #ocaml
waleee has joined #ocaml
jutty has left #ocaml [#ocaml]
nickiminjaj has joined #ocaml
wingsorc has joined #ocaml
<dh`> also there's often a case to be made for making a private type for it
<dh`> sometimes you see people writing stuff like (string option option, int) either and you wonder if anyone's going to be able to read it two years later
Serpent7776 has quit [Ping timeout: 252 seconds]
<discocaml> <contextfreebeer> Lol
bartholin has quit [Quit: Leaving]
trillion_exabyte has quit [Read error: Connection reset by peer]
trillion_exabyte has joined #ocaml
pi3ce has joined #ocaml
waleee has quit [Ping timeout: 268 seconds]
Tuplanolla has quit [Quit: Leaving.]