Page 1 of 2
Looking for floating point libraries
Posted: Wed Aug 30, 2023 3:43 pm
by hjalfi
As title.
I already know of:
- Wozniak & Rankin's one from Dr. Dobbs in 1976 (4-byte binary, difficult copyright licensing/issues)
- Microsoft's one in their BASIC (no license)
- Acorn's in their BASIC (no license)
- the Atari MATHPACK clone from Altirra (GPL; 6-byte BCD)
- the C64-compatible routines from the X16 kernal replacement (mostly copied from Microsoft, AFAICT)
- Louis Chorich's Atari floating point library (commercial, 6-byte, presumably BCD but the docs don't say)
- Apple's SANE (source lost)
- Some Random Internet Guy's library (no license, 5-byte BCD, no negative numbers)
Anyone know of more?
Re: Looking for floating point libraries
Posted: Wed Aug 30, 2023 4:36 pm
by gfoot
I wrote some floating point routines earlier this year, I'm not sure if they count as a library though. I think I posted it on Stardot as it was using the BBC BASIC assembler, and had routines to load values from BASIC variables. I only implemented the basics though (addition, subtraction, multiplication). I made a two byte version and a three byte version. The API was load-store register-based, a bit like ARM I guess.
Re: Looking for floating point libraries
Posted: Wed Aug 30, 2023 7:12 pm
by barrym95838
Re: Looking for floating point libraries
Posted: Wed Aug 30, 2023 7:25 pm
by BigDumbDinosaur
Re: Looking for floating point libraries
Posted: Wed Aug 30, 2023 7:27 pm
by BigDumbDinosaur
Re: Looking for floating point libraries
Posted: Thu Aug 31, 2023 2:08 pm
by hjalfi
Here's another one, written this decade:
https://hackaday.io/project/181098-home ... r-for-6502 32-bit BCD, no license (but unusually, the author can be contacted without the use of a spirit medium!).
Re: Looking for floating point libraries
Posted: Thu Aug 31, 2023 2:27 pm
by hjalfi
https://web.archive.org/web/20200128060 ... calc65.htm: 64-bit BCD, full set of trigonometric functions... no license and 'all rights reserved'.
Re: Looking for floating point libraries
Posted: Fri Sep 01, 2023 3:36 am
by dmsc
Hi!
As title.
I already know of:
- Wozniak & Rankin's one from Dr. Dobbs in 1976 (4-byte binary, difficult copyright licensing/issues)
- Microsoft's one in their BASIC (no license)
- Acorn's in their BASIC (no license)
- the Atari MATHPACK clone from Altirra (GPL; 6-byte BCD)
The Altirra ROM replacement is not under the GPL, but under the MIT license, much more permissive.
- the C64-compatible routines from the X16 kernal replacement (mostly copied from Microsoft, AFAICT)
- Louis Chorich's Atari floating point library (commercial, 6-byte, presumably BCD but the docs don't say)
- Apple's SANE (source lost)
The VBCC 6502 compiler uses those, and includes a library with all the split objects.
- Some Random Internet Guy's library (no license, 5-byte BCD, no negative numbers)
Anyone know of more?
The Mad Pascal compiler (at
https://github.com/tebe6502/Mad-Pascal ) includes:
- 32-bit FLOAT:
https://github.com/tebe6502/Mad-Pascal/ ... single.asm
- 16-bit FLOAT:
https://github.com/tebe6502/Mad-Pascal/ ... dd_sub.asm and other files.
Have Fun!
Re: Looking for floating point libraries
Posted: Fri Sep 01, 2023 9:21 am
by hjalfi
The Altirra ROM replacement is not under the GPL, but under the MIT license, much more permissive.
Oops. I knew that, honest.
That's a nice find. The comment at the top of the first suggests the 32-bit code partially came from David Schmenk's Java VM for the Apple 2 (
https://sourceforge.net/projects/vm02/, GPL-2), but the 16-bit stuff looks native.
Re: Looking for floating point libraries
Posted: Fri Sep 01, 2023 8:15 pm
by johnwbyrd
Here's a standards-compliant implementation. Only compiles on llvm-mos as far as I know.
https://github.com/rweather/berkeley-softfloat-3-6502
Re: Looking for floating point libraries
Posted: Sun Sep 03, 2023 11:36 am
by BillG
I know you want something with a permissive license.
I am not a patent lawyer and I do not play one on television; if you were to paraphrase code from one processor architecture to a different one, is the result considered to be infringing? If not, that may be a relatively easy way to get there. I have always presumed that to be safe; it is not unlike coding from an algorithm in a book or journal.
Floating point code has been published for the Motorola 8-bit processors. Same for 8080/Z80. Source code for 8087 emulation from the Borland compilers (80x86) is also out there.
Are you picky between BCD versus binary?
A long time ago, I set out to write IEEE 754 compliant floating point for the 6800. I have single precision generally working but have yet to work out how to implement the guard, round and sticky bits. Because the AVR instruction set looked so easy to program, I also built a version for that. Future steps:
* Figure out the guard, round and sticky bits
* Improve the speed
* Implement 6-byte, double and extended precision
* Port to other processors
Re: Looking for floating point libraries
Posted: Sun Sep 03, 2023 12:09 pm
by drogon
This is interesting as it ought to be possible to port it to cc65 which is probably (at the moment) more accessible to more 6502 users than the llvm-mos branch is.
The idea if implementing floating point in a language that doesn't intrinsically support it [1] isn't new either - in the early 80's BCPL didn't support floating point either, but there were libraries - one I used was the package for the BBC Micros implementation of BCPL which supported various formats and previsions. FP numbers were held in vectors (arrays) and you called functions to do the FP operations.
https://www.computinghistory.org.uk/det ... s-Package/
-Gordon
[1] Yes, C supports floating point but cc65 doesn't, so it would have to be implemented by external means.
Re: Looking for floating point libraries
Posted: Tue Sep 05, 2023 2:54 pm
by Chromatix
I have single precision generally working but have yet to work out how to implement the guard, round and sticky bits.
I discussed the guard and sticky bits here, including pseudocode to perform correct rounding using them:
viewtopic.php?f=2&t=5352#p64001
Re: Looking for floating point libraries
Posted: Wed Sep 06, 2023 10:10 pm
by resman
I wrote some 32 bit single precision FP routines for VM02. Not much error handling. Search for FLOATING_POINT:
https://github.com/dschmenk/VM02/blob/master/src/ops.s
Re: Looking for floating point libraries
Posted: Sat Sep 30, 2023 2:29 pm
by BillG
I have single precision generally working but have yet to work out how to implement the guard, round and sticky bits.
I discussed the guard and sticky bits here, including pseudocode to perform correct rounding using them:
viewtopic.php?f=2&t=5352#p64001
Thanks for that. Completing floating point implementation will be a huge leap forward for some cross-compilers in progress.