Sunday, March 16, 2025

QuickJS pi, with BigInt, BigFloat, BigDecimal

How quickly can JS calculate digits of Pi? This is quite fast



And this is even faster!


And diverse, with various "big numbers" tools.





QuickJS Javascript Engine 
by Fabrice Bellard and Charlie Gordon.



Google AI Overview

JavaScript's native Number type adheres to the IEEE 754 standard for double-precision floating-point numbers, which can lead to precision issues when dealing with very large or very small numbers, or with decimal fractions that cannot be represented exactly in binary. To overcome these limitations, several libraries provide support for arbitrary-precision floating-point arithmetic in JavaScript.

Libraries for BigFloat Arithmetic

big.js:

A small and easy-to-use library that provides arbitrary precision decimal arithmetic. It focuses on simplicity and is suitable for handling financial calculations or situations where accuracy in decimal representation is crucial.

bignumber.js:
A more feature-rich library that supports bases from 2 to 64, configuration options, and handles NaN and Infinity. It offers precision control and is suitable for advanced mathematical operations.

decimal.js:
Similar to bignumber.js, it provides arbitrary-precision decimal arithmetic with support for non-integer powers, logarithms, and random number generation. It always applies the specified precision, making it suitable for scientific and engineering applications.

bigfloat:
Optimized for computational geometry and geoinformatics, this library offers fast arbitrary precision math with binary floating-point support.

big-float-ts:
An ESM-only package for Node.js or browser environments that provides arbitrary-precision floating-point arithmetic.

bigdecimal.js:
A pure-JavaScript implementation of immutable, arbitrary-precision, signed decimal numbers, suitable for decimal math with high precision.



Run Linux, play Doom in PDF


If it is worth keeping, save it in Markdown

Markdown files are essentially plaintext with some extra syntax for common elements like sections, bullet points, and links. The format deliberately avoids precise control over display details like font selection4. Following the rule of least power, I consider this limitation a feature. For contrast, consider PDF - a format so powerful that it can run Doom.

Linux running in a PDF file - YouTube

Doom in a PDF file : r/itrunsdoom

Doom (1993) in a PDF file - YouTube

Play it here: https://doompdf.pages.dev/doom.pdf 

The PDF file format supports Javascript with its own separate standard library. Modern browsers (Chromium, Firefox) implement this as part of their PDF engines. However, the APIs that are available in the browser are much more limited. It turns out that old versions of Emscripten can compile C to asm.js code that will happily run inside the limited JS runtime of the PDF engine. ... used the doomgeneric (https://github.com/ozkl/doomgeneric) fork of the original Doom source, as that made writing the IO fairly easy. All I had to do was implement a framebuffer and keyboard inputs. Unlike previous interactive PDF demos, the output for DoomPDF is achieved by creating a text field for each row of pixels in the screen, then setting their contents to various ASCII characters. This gives me a 6 color monochrome display, that can be updated reasonably quickly (80ms per frame). The source code is available at: https://github.com/ading2210/doompdf