6

What are the available portable implementations of the C99 long double math library functions (expl, cosl, logl, etc.), if any? I've looked in fdlibm (Sun-based), NetBSD (UCB-based), etc. sources and not seen them.

R.. GitHub STOP HELPING ICE
  • 195,354
  • 31
  • 331
  • 669

2 Answers2

4

You should be able to see it in the Sun-based libraries (used in pretty much all the open C libraries I am aware of, including glibc and FreeBSD one).

I generally prefer BSD code for math code (more readable IMO). See here for 80-bits (Intel) long double format. For a given function, different implementation/architectures may be in different directories.

One thing to realize is that long double is not standardized (more exactly, only since the 2008 rev of IEEE754, which is not really implemented in most common CPU yet). Which means each CPU requires a different implementation for a lot of stuff (IA32, AMD64, PPC, Alpha, Sparc are all different in that aspect...).

David Cournapeau
  • 71,471
  • 8
  • 59
  • 68
  • Well, supporting 80-bit and 128-bit should cover just about everything... And I would suspect that a 128-bit implementation should work for 80-bit systems, but perhaps this isn't entirely obvious or even true. :-) – R.. GitHub STOP HELPING ICE May 10 '11 at 04:55
  • a 128 bits does not work as 80 bits, the bits representation is completely different. A lot of low level macros needs to deal with the binary details (isnan/isfinite/etc...). If you look at some implementation of nextafter and similar macro/functions, you will see how the binary differences were abstracted (it is not always possible). – David Cournapeau May 10 '11 at 10:08
  • Yes, I meant the higher-level mathematical functions. Of course the bit-level functions will differ. – R.. GitHub STOP HELPING ICE May 10 '11 at 11:30
1

Try the Cephes Mathematical Library.

lhf
  • 64,395
  • 9
  • 93
  • 126
  • Interesting but it seems to have some major license issues: http://www.mail-archive.com/debian-legal@lists.debian.org/msg29047.html Any idea if these have been resolved? – R.. GitHub STOP HELPING ICE May 10 '11 at 23:35
  • @R, I always thought code from netlib was free but the docs in http://www.netlib.org/cephes/cephes.doc say "Copyright 1984 - 1992 by Stephen L. Moshier". His site http://www.moshier.net/#Cephes does not mention licensing at all. But it says "Latest Linux distribution, dated 6/4/00", so I assume it can be used freely, since it's in Linux, but IANAL. – lhf May 11 '11 at 00:24
  • Ah, the README at http://www.netlib.org/cephes/readme says "In either event, it is copyrighted by the author. What you see here may be used freely but it comes with no support or guarantee." So, free indeed. – lhf May 11 '11 at 00:26
  • "Used freely" is pretty vague. Is preparing derivative works covered under "used freely"? This sounds like DJB nonsense, presenting an ambiguous statement that the code is "free" while leaving enough wiggle-room to screw over anyone who tries to use it, if so desired, at a later time... – R.. GitHub STOP HELPING ICE May 11 '11 at 00:31
  • @R, yes, it's vague. You could ask the author. My impression is that he won't mind, but again IANAL. – lhf May 11 '11 at 01:50
  • 1
    Sometimes it pays to just ask the author to open source it, I have tried it successfully several times. Also OP did not specify open source license as a requirement. – Prof. Falken Feb 15 '12 at 17:15