Re: Floating point: sine, cosine etc.

From: Rhialto <rhialto_at_falu.nl>
Date: Sat, 24 Sep 2022 15:10:37 +0200
Message-ID: <Yy8BzXlGks8cGbd6_at_falu.nl>
On Fri 23 Sep 2022 at 22:01:21 +0200, ruud_at_baltissen.org wrote:
> In short: I had to invent the wheel again how to convert an ASCII string
> into FP and vice versa and it still isn't completely finished. For both
> conversions I could find literature and examples but so far I havent found

It just so happens that a few months ago I needed to convert an ASCII
string into a PDP-11 floating point number, without using floating point
operations. The algorithm I had before required 64-bit floats (long
double) and somebody complained that those are (strangely!) not
supported by the Apple M1 compilers.

These PDP-11 floats are 32 bits and have probably a slightly different
format than you need, but the main work is finding the values of the
mantissa and exponent, and how big exactly they are is pretty much only
relevant at the end, when they are put together in the final format.

https://gitlab.com/Rhialto/macro11/-/blob/master/parse.c#L654

The code here has been stronly inspired by the original MACRO-11
assembler from Digital. It is quite clever in that it collects the bits
of the mantissa without losing significant bits if possible, even if you
write a very long number (or with a lot of decimals); also when
converting the decimal exponent (like in E10) to a binary one. Those
steps require a lot of multiplications and/or divisions by 10.  The
original code used the trick of dividing by 5 by multiplying with
0x19999999999999999 with just shifts and adds, but on modern CPUs that's
not really needed any more.

-Olaf.
-- 
___ "Buying carbon credits is a bit like a serial killer paying someone else to
\X/  have kids to make his activity cost neutral." -The BOFH    falu.nl_at_rhialto


Received on 2022-09-24 16:00:28

Archive generated by hypermail 2.3.0.