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)
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?
I looked at some examples on Github and they all seem to make different packages for each OS.
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.
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?
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.
Right, ok. But you’re saying uninstall will be messy. Is that OK?
Like, is there a way that doesn’t run into that issue?
I think it’s ok. This happens with a package or two already.
If it becomes an issue, then probably raco setup
should offer a way to register things that will get removed.
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?
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.
ok thanks!
@pavpanchekha I have some floating point issues that I’m struggling with and I’m curious if herbie is the right tool
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.
Herbie might help, but hard to say. What’s the algorithm? (Which operator?)
Right now I’m trying to implement fl2*
using the algorithms in this paper: https://hal.archives-ouvertes.fr/hal-01351529v3/document
You can see my implementation in that PR (just pushed the current status).
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)
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.
Wait how does it make NaN? Or is it a previous version that made NaN?
The code you see produces NaN
If you look at https://github.com/racket/math/blob/f01332f5cab3c3bf726b05bcee27308e98fe1c33/math-lib/math/private/flonum/expansion/expansion-base.rkt#L267 then cl1 is +inf.0, cl3 in -inf.0, and then Fast2Sum produces NaN
If I change the cond test to fl> and fl< instead of <= and >=, then it works
I initially read it that way
But I’m not sure if that’s correct
but I took that check from the existing math-lib code which uses <=
So at this point I feel like I’m just stabbing in the dark
The worry is that xh * yh overflows
But xl or yl have opposite sign from xh/yh
And with them included, it doesn’t overflow
Sometimes you try to guarantee the h and l have same signs
If so < is correct
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)
Hmm
So yeah it’s about invariants
So I feel like I’m just stabbing in the dark trying to make the tests pass
If same-sign is an invariant, then that counterexample is invalid
If not, the correct fix is subtler
You gotta check tl1 and tl2, if either is infinite then return z, 0
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)
Right; typically that’s not an invariant, looks like in this paper not because they use RN everywhere
So you need to check tl1 and tl2
so is that paper just not worrying about overflow/underflow/nan?
(Intuition: if tl1 or tl2 are infinite, then z is not only infinite but infinite by a factor of 2^53 or so
In which case xl and yl don’t matter)
is there an example where this happens despite the fl<
check?
Hmm, I think [2^512, –2^460, 2^512, –2^460] will work
Plus minus one on the exponents
I just pushed what I think you’re suggesting
The idea is that inf is 2^1024 or so
So here xh*yh is just barely inf
We’re just squaring here so we get xh^2 – 2 xh xl + xl^2
I think if we pick xl to be about xh * eps we should get a counterexample
Though there aren’t many counter examples, I would bet
And maybe it just barely rounds correctly.
Not sure…
Ok I may try to add a test for that tomorrow
I think my branch now passes the tests for everything but fl2sqr, fl2sqrt, and fl2/
But I’m still confused about the paper — what do those proofs mean?
Good Q. Does the paper discuss special values?
Bad tendency to assume them away in FP papers
" provided that and overflow do not occur"
(typo in the original)
sigh
Ah
Yep
That’s it
makes me more appreciative of the work Neil did
I think you need to keep the <=