NO

Author Topic: atof  (Read 6937 times)

Offline MrBcx

  • Global Moderator
  • Member
  • *****
  • Posts: 189
    • Bcx Basic to C/C++ Translator
Re: atof
« Reply #15 on: November 23, 2020, 08:22:15 PM »

I have read too that a programmer gave numbers in the form of a string.
 

I have ugly code that I wrote in 1992 that creates 3 functions -- fpAdd, fpSub, and fpMul.
Each takes 2 string arguments.  The BASIC code was written for MSDOS but compiles with Pelles
when converted using my BCX translator.

Examples:

PRINT fpAdd$ ("999.123456789","100")

PRINT fpSub$ ("500.987654321","100")

PRINT fpMul$ ("999999999999999999.123456789","999999999999999999.123456789")


OUTPUT

1099.123456789
400.987654321
999999999999999998246913578000000000.768328000750190521


Impressively, the fpMul result matches the result obtained here:

https://keisan.casio.com/calculator

Bcx Basic to C/C++ Translator
https://www.BcxBasicCoders.com

Grincheux

  • Guest
Re: atof
« Reply #16 on: November 23, 2020, 08:28:50 PM »
A good thing and impressive calculator!
I also have found LibBF and GNU MPFR but there is no Windows Version!
It is possible using MinGW but too complicated for me.

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
« Last Edit: November 24, 2020, 07:20:15 AM by TimoVJL »
May the source be with you

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: atof
« Reply #18 on: November 24, 2020, 12:10:27 AM »
What about transforming in two 64 bits numbers.
Than You Frankie for your help.
I would avoid to to reinvent the wheel and write your own math library.
You can use the QD library ported by Timovjl.
I also found another quad precision float library that seems interesting: the HPALIB (High Precision Arithmetic library).
The IEEE 754 2008 binary128 uses 1 bit for sign, 15bits for exponent and 113bits for mantissa. 113bits means 33 significant digits. This means that you can work i.e. with numbers of 16 digits before decimal dot and 16 digits after without precision loss.
« Last Edit: November 24, 2020, 12:25:48 AM by frankie »
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Grincheux

  • Guest
Re: atof
« Reply #19 on: November 24, 2020, 06:18:01 PM »
There are too many numbers after the decimal point!


Thank You Frankie & Timo I will use the library

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: atof
« Reply #20 on: November 25, 2020, 05:11:02 PM »
QDC library should follow lisence:
https://www.davidhbailey.com/dhbsoftware/LBNL-BSD-License.docx

PS.
David H Bailey accept that QDC project.

May the source be with you