Author Topic: Numeric formatting and precision  (Read 4679 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Numeric formatting and precision
« on: November 08, 2015, 11:17:17 PM »
Another BP.org extension thread.

Here is Script BASIC 64 bit at 100 decimal place precision. Attached is a PDF with an article called, How to Print Floating-Point Numbers Accurately.

I have a suspicion that the Script BASIC FORMAT function needs work for 64 bit masks.  I think it is only working for 32 bit numbers.

Code: ScriptBasic
  1. PRINT FORMAT("%.100f",0.1),"\n"
  2.  


jrs@laptop:~/sb/sb22/test$ scriba richtest.sb
0.1000000000000000055511151231257827021181583404541015625000000000000000000000000000000000000000000000
jrs@laptop:~/sb/sb22/test$


Quote from: Mike
What is there more precise than, say, a ...

Code: ScriptBasic
  1. PRINT FORMAT("%.54f",237488392002130455361/456392442844),"\n"
  2.  


jrs@laptop:~/sb/sb22/test$ time scriba miketest.sb
-20209300.529560755938291549682617187500000000000000000000000000

real   0m0.003s
user   0m0.000s
sys   0m0.003s
jrs@laptop:~/sb/sb22/test$

« Last Edit: November 09, 2015, 04:09:16 AM by John »

Mike Lobanovsky

  • Guest
Re: Numeric formatting and precision
« Reply #1 on: November 20, 2015, 07:56:44 PM »
In fact, it should be

647347900.7381097690578838949200392889551072684939893365821313759037206917770652086561173437186439033132987465 ...

accurate to 100 decimal places. The actual decimal representation for all intents and purposes seems to be infinite, similar to PI.

(In my opinion, it isn't appropriate for an all-purpose BASIC to try and compete with specialized arbitrary precision math libraries in jobs like that. The BASIC would be much better off getting busy to provide an adequate and easy to use interface to such libraries out of the box, whenever needed, preferably following the standards of languages those libraries are most likely to be written in, as long as it doesn't have a standard of its own. ;) )
« Last Edit: November 20, 2015, 08:05:27 PM by Mike Lobanovsky »

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: Numeric formatting and precision
« Reply #2 on: November 20, 2015, 09:55:51 PM »
I agree! I still think Script BASIC's FORMAT function has 32 bit tendencies. (possibility using the wrong masking designators for 64 bit) It has the same smell as when you and I were trying to get Tiny Scheme running 64 bit on Windows.


Mike Lobanovsky

  • Guest
Re: Numeric formatting and precision
« Reply #3 on: November 21, 2015, 03:36:23 AM »
No, IIRC it was you and I. I used to get obsessed with nanoscheme and oxyscheme. :D
« Last Edit: November 21, 2015, 03:38:13 AM by Mike Lobanovsky »