Live data from Hacker News

LibBF – a small library to handle arbitrary precision floating point numbers

bellard.org

51–60 of 63 posts

Re: LibBF – a small library to handle arbitrary precision floating point numbers

#51

Perhaps a side digression to this conversation, but... in spite of all the cool languages we talk about that have many on-paper advantages of either safety, convenience, or support of paradigms, is there really any option besides C for this kind of thing? It still seems that, if you want to write Core Infrastructual Code that can be run anywhere, on anything, that links with any other software without any caveats, di…

In my limited experience, no. All of the languages you mention put developer experience above portability, so usually require a basic runtime. C on the other hand is not interested in saving you from the machine, which allows for extremely minimal programs. Even C++ isn't great here compared to C. Then again, debugging segfaults isn't for everyone, so most are fine giving up C.

> All of the languages you mention put developer experience above portability, so usually require a basic runtime.

Rust's runtime is comparable to C's. It is less portable because it uses LLVM as a backend, not because of the runtime.

> Then again, debugging segfaults isn't for everyone, so most are fine giving up C.

Depending on the application, having vulnerabilities due to undefined behavior is a much bigger problem than having to debug segfaults.

Re: LibBF – a small library to handle arbitrary precision floating point numbers

#52

Perhaps a side digression to this conversation, but... in spite of all the cool languages we talk about that have many on-paper advantages of either safety, convenience, or support of paradigms, is there really any option besides C for this kind of thing? It still seems that, if you want to write Core Infrastructual Code that can be run anywhere, on anything, that links with any other software without any caveats, di…

You could use D in -betterC mode. It allows compiling code that doesn't rely on runtime (has some limitations though, most notably lack of garbage collector, forcing you to use manual allocation).

Re: LibBF – a small library to handle arbitrary precision floating point numbers

#53
post #46

This needs some major work to be packagable into a library, esp. for non amd64 hosts. There's also no src repo, as with all his previous hacks. Who will do the autotooling and repo hosting? I've added some sugar in my fork on github https://github.com/rurban/libbf/tree/my but I'm not sure yet if I will use it. But the low constant overhead for small numbers, the small size, no assembler tricks and the MIT license mak…

I think the name is also already taken, for brainfuck and bloom filter.

Re: LibBF – a small library to handle arbitrary precision floating point numbers

#54
post #51

Earlier quoted context omitted.

In my limited experience, no. All of the languages you mention put developer experience above portability, so usually require a basic runtime. C on the other hand is not interested in saving you from the machine, which allows for extremely minimal programs. Even C++ isn't great here compared to C. Then again, debugging segfaults isn't for everyone, so most are fine giving up C.

> All of the languages you mention put developer experience above portability, so usually require a basic runtime. Rust's runtime is comparable to C's. It is less portable because it uses LLVM as a backend, not because of the runtime. > Then again, debugging segfaults isn't for everyone, so most are fine giving up C. Depending on the application, having vulnerabilities due to undefined behavior is a much bigger probl…

then port it to gcc?

Re: LibBF – a small library to handle arbitrary precision floating point numbers

#55
post #23
post #21

For those that don't know, Fabrice Bellard is the author of ffmpeg [1], the tiny c compiler (tcc) [2], linux in the browser [3] among many others [4]. Does anyone know how LibBF stacks up against GMP? [5] [1] http://ffmpeg.org/ [2] https://bellard.org/tcc/ [3] https://bellard.org/jslinux/ [4] https://bellard.org/ [5] https://en.wikipedia.org/wiki/GNU_Multiple_Precision_Arithme...

Yes, a comparison with GMP is the first link: https://bellard.org/libbf/benchmark.html

Is there a comparison for anything other than multiplication? Or is multiplication fairly representative of other operations on AP numbers?

Re: LibBF – a small library to handle arbitrary precision floating point numbers

#56

Perhaps a side digression to this conversation, but... in spite of all the cool languages we talk about that have many on-paper advantages of either safety, convenience, or support of paradigms, is there really any option besides C for this kind of thing? It still seems that, if you want to write Core Infrastructual Code that can be run anywhere, on anything, that links with any other software without any caveats, di…

The cool languages themselves tend to have this kind of feature written in C "under the hood".

GHC Haskell Runtime:

https://github.com/ghc/ghc/tree/master/rts

Re: LibBF – a small library to handle arbitrary precision floating point numbers

#57
post #51

Earlier quoted context omitted.

In my limited experience, no. All of the languages you mention put developer experience above portability, so usually require a basic runtime. C on the other hand is not interested in saving you from the machine, which allows for extremely minimal programs. Even C++ isn't great here compared to C. Then again, debugging segfaults isn't for everyone, so most are fine giving up C.

> All of the languages you mention put developer experience above portability, so usually require a basic runtime. Rust's runtime is comparable to C's. It is less portable because it uses LLVM as a backend, not because of the runtime. > Then again, debugging segfaults isn't for everyone, so most are fine giving up C. Depending on the application, having vulnerabilities due to undefined behavior is a much bigger probl…

+1 for mentioning Rust. Which in contrast to C++ has all the goodies without the runtime dependencies.

I wouldn't say LLVM is such a great restriction, except when talking about embedded (too few architectures supported here). The major desktop and server architectures are supported (AFAIK), even WASM.

Re: LibBF – a small library to handle arbitrary precision floating point numbers

#58
post #37
post #20

Earlier quoted context omitted.

Because JSON's spec defines a "number" as an arbitrary-precision floating point number, no limit on how many digits can be before or after the decimal or on what positive or negative integers you can put after the "e". Despite the name "JavaScript Object Notation," it does not inherit JavaScript's traditional interpretation that a "number" is an IEEE 754 double. (JSON also does not permit infinities or NaN, which Jav…

Wouldn't jq be better served by a library supporting arbitrary precision decimal values? LibBF is for base-2 floating point.

Probably yes, because you always want to convert to and from base 10 strings. mpdecimal [1] (which was developed for Python) might be a better choice, because it uses base 10 internally.

[1] http://www.bytereef.org/mpdecimal/

Re: LibBF – a small library to handle arbitrary precision floating point numbers

#59
post #51

Earlier quoted context omitted.

> All of the languages you mention put developer experience above portability, so usually require a basic runtime. Rust's runtime is comparable to C's. It is less portable because it uses LLVM as a backend, not because of the runtime. > Then again, debugging segfaults isn't for everyone, so most are fine giving up C. Depending on the application, having vulnerabilities due to undefined behavior is a much bigger probl…

then port it to gcc?

We’d love to see a gcc front end for Rust. Someone attempted one in the pre-1.0 days, which was... not simple. Someone has to step up and do it though.

Re: LibBF – a small library to handle arbitrary precision floating point numbers

#60
post #36

There is also BSDNT[0] (which is obviously BSD licensed) in case anyone is still interested... I think this takes the cake though (as it is MIT licensed and superior). [0]: https://github.com/wbhart/bsdnt

I also just realized that this is only for big numbers, not arbitrary precision.
Post reply on HN