pavpanchekha
2022-5-31 18:01:32

Hi, quick question. In my info.rkt how do I make the move-foreign-libs key use a system-specific extension (so that it uses .so on Unix, .dylib on macOS, and .dll on Windows)


pavpanchekha
2022-5-31 18:04:40

I have an install.rkt file that builds a file called (path-replace-extension "libsoftposit.so" (system-type 'so-suffix)). Note that the extension is platform-specific. I now want to list this in info.rkt like this: (define move-foreign-libs '("libsoftposit.so")). How?


pavpanchekha
2022-5-31 18:05:57

I looked at some examples on Github and they all seem to make different packages for each OS.


mflatt
2022-5-31 18:08:18

It’s not immediately obvious to me that having move-foreign-libs depend on the output of install-collection is a good idea. (They can be skipped independently, for example.) How about generating the file directly to the intended destination? Uninstalling might not clean up as well, but maybe that would be ok.


pavpanchekha
2022-5-31 18:09:28

Maybe I’m going about this the wrong way. I have a Racket package that builds an existing C library to a shared library, and then wants to FFI to it to expose a Racket interface. What’s the best way to do this?


mflatt
2022-5-31 18:11:27

That sounds ok, as long as you expect users to have a C compiler installed. But I’m suggesting that the output of compiling and linking should go to (find-lib-dir) or (find-user-lib-dir), depending on whether the function indicated by install-collection function receives a true value as its third argument.


pavpanchekha
2022-5-31 18:12:01

Right, ok. But you’re saying uninstall will be messy. Is that OK?


pavpanchekha
2022-5-31 18:12:16

Like, is there a way that doesn’t run into that issue?


mflatt
2022-5-31 18:12:20

I think it’s ok. This happens with a package or two already.


mflatt
2022-5-31 18:12:53

If it becomes an issue, then probably raco setup should offer a way to register things that will get removed.


pavpanchekha
2022-5-31 18:14:14

Ok, so right now there’s no install-collection; I do the compiling and linking in pre-install-collection. Do I need to change that?


mflatt
2022-5-31 18:15:54

Probably either is fine. You’re need to use pre-install-collection if compiling Racket code depends on the library, but more likely, the library is needed only for running Racket code. I would use install-collection just as a default choice.


pavpanchekha
2022-5-31 19:22:48

ok thanks!


samth
2022-5-31 20:43:07

@pavpanchekha I have some floating point issues that I’m struggling with and I’m curious if herbie is the right tool


samth
2022-5-31 20:44:07

In particular I’m trying to do PR #71 and both the old algorithm and the better algorithms in the literature end up with NaN in various cases.


pavpanchekha
2022-5-31 20:45:20

Herbie might help, but hard to say. What’s the algorithm? (Which operator?)


samth
2022-5-31 20:46:14

Right now I’m trying to implement fl2* using the algorithms in this paper: https://hal.archives-ouvertes.fr/hal-01351529v3/document


samth
2022-5-31 20:47:17

You can see my implementation in that PR (just pushed the current status).


samth
2022-5-31 20:47:53

And the following example (found by random testing) produces NaN instead of Inf: (fl2* -7.236668432619935e+277 -9.343040859629084e+260 -2.063470113016713e+168 1.3139786370052367e+152)


samth
2022-5-31 20:49:44

Well, I just made what seemed like a straightforward change and it fixed things, but I don’t really know what I’m doing so I’m unsure.


pavpanchekha
2022-5-31 20:52:04

Wait how does it make NaN? Or is it a previous version that made NaN?


samth
2022-5-31 20:52:27

The code you see produces NaN


samth
2022-5-31 20:54:34

samth
2022-5-31 20:55:07

If I change the cond test to fl> and fl< instead of <= and >=, then it works


pavpanchekha
2022-5-31 21:00:12

I initially read it that way


pavpanchekha
2022-5-31 21:00:27

But I’m not sure if that’s correct


samth
2022-5-31 21:00:35

but I took that check from the existing math-lib code which uses <=


samth
2022-5-31 21:00:51

So at this point I feel like I’m just stabbing in the dark


pavpanchekha
2022-5-31 21:01:03

The worry is that xh * yh overflows


pavpanchekha
2022-5-31 21:01:20

But xl or yl have opposite sign from xh/yh


pavpanchekha
2022-5-31 21:01:37

And with them included, it doesn’t overflow


pavpanchekha
2022-5-31 21:02:07

Sometimes you try to guarantee the h and l have same signs


pavpanchekha
2022-5-31 21:02:17

If so < is correct


samth
2022-5-31 21:02:33

for example the fast-fl*/error code is what’s in that paper for the same operation, but it doesn’t do the right thing always, but fl*/error does (but I don’t know where that algorithm is from)


pavpanchekha
2022-5-31 21:04:09

Hmm


pavpanchekha
2022-5-31 21:04:27

So yeah it’s about invariants


samth
2022-5-31 21:04:37

So I feel like I’m just stabbing in the dark trying to make the tests pass


pavpanchekha
2022-5-31 21:04:58

If same-sign is an invariant, then that counterexample is invalid


pavpanchekha
2022-5-31 21:05:09

If not, the correct fix is subtler


pavpanchekha
2022-5-31 21:08:08

You gotta check tl1 and tl2, if either is infinite then return z, 0


samth
2022-5-31 21:09:34

I’m pretty sure they don’t have to be the same sign, since then you couldn’t represent a number slightly smaller than x-hi (although I suppose you could by taking a smaller x-hi and adding)


pavpanchekha
2022-5-31 21:10:21

Right; typically that’s not an invariant, looks like in this paper not because they use RN everywhere


pavpanchekha
2022-5-31 21:10:31

So you need to check tl1 and tl2


samth
2022-5-31 21:10:48

so is that paper just not worrying about overflow/underflow/nan?


pavpanchekha
2022-5-31 21:11:14

(Intuition: if tl1 or tl2 are infinite, then z is not only infinite but infinite by a factor of 2^53 or so


pavpanchekha
2022-5-31 21:11:27

In which case xl and yl don’t matter)


samth
2022-5-31 21:12:36

is there an example where this happens despite the fl&lt; check?


pavpanchekha
2022-5-31 21:14:06

Hmm, I think [2^512, –2^460, 2^512, –2^460] will work


pavpanchekha
2022-5-31 21:14:19

Plus minus one on the exponents


samth
2022-5-31 21:14:35

I just pushed what I think you’re suggesting


pavpanchekha
2022-5-31 21:14:38

The idea is that inf is 2^1024 or so


pavpanchekha
2022-5-31 21:14:54

So here xh*yh is just barely inf


pavpanchekha
2022-5-31 21:15:45

We’re just squaring here so we get xh^2 – 2 xh xl + xl^2


pavpanchekha
2022-5-31 21:16:15

I think if we pick xl to be about xh * eps we should get a counterexample


pavpanchekha
2022-5-31 21:16:46

Though there aren’t many counter examples, I would bet


pavpanchekha
2022-5-31 21:16:59

And maybe it just barely rounds correctly.


pavpanchekha
2022-5-31 21:17:04

Not sure…


samth
2022-5-31 21:17:06

Ok I may try to add a test for that tomorrow


samth
2022-5-31 21:17:41

I think my branch now passes the tests for everything but fl2sqr, fl2sqrt, and fl2/


samth
2022-5-31 21:19:54

But I’m still confused about the paper — what do those proofs mean?


pavpanchekha
2022-5-31 21:20:30

Good Q. Does the paper discuss special values?


pavpanchekha
2022-5-31 21:20:45

Bad tendency to assume them away in FP papers


samth
2022-5-31 21:21:29

" provided that and overflow do not occur"


samth
2022-5-31 21:21:34

(typo in the original)


samth
2022-5-31 21:21:40

sigh


pavpanchekha
2022-5-31 21:21:42

Ah


pavpanchekha
2022-5-31 21:21:44

Yep


pavpanchekha
2022-5-31 21:21:53

That’s it


samth
2022-5-31 21:22:01

makes me more appreciative of the work Neil did


pavpanchekha
2022-5-31 22:08:26

I think you need to keep the <=