Accuracy of integer operations

40 views
Skip to first unread message

Harlan Gilbert

unread,
Oct 22, 2020, 6:14:22 PM10/22/20
to Glowscript Users
Bruce,

Whereas Python has virtually infinite accuracy for integer operations such as multiplication and powers, Glowscript is giving me only six digits of accuracy, going quickly into floating point numbers for largish (actually not even very large) numbers.

Having only six digits of accuracy is a real problem for number theory work (for example, an implemention of the Diffie-Hellman public key cipher).

There may be no full solution, but if Python at least used double precision values by default, it would improve things.

Thanks for considering,
Harlan

Bruce Sherwood

unread,
Oct 22, 2020, 6:39:26 PM10/22/20
to Glowscript Users
GlowScript DOES use double precision. But by default the print statement displays 6 figures. See the documentation on "print_options" at https://www.glowscript.org/docs/VPythonDocs/text_output.html to change the default. 

Bruce

Harlan Gilbert

unread,
Oct 22, 2020, 7:07:23 PM10/22/20
to glowscri...@googlegroups.com
Thanks!  This fixed it.

On Thu, Oct 22, 2020 at 6:39 PM Bruce Sherwood <bruce.s...@gmail.com> wrote:
GlowScript DOES use double precision. But by default the print statement displays 6 figures. See the documentation on "print_options" at https://www.glowscript.org/docs/VPythonDocs/text_output.html to change the default. 

Bruce

--

---
You received this message because you are subscribed to a topic in the Google Groups "Glowscript Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/glowscript-users/PFXluzssirU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to glowscript-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/glowscript-users/CA%2BWuaSdqUg-b1kmXkBcoZ2y%3DC62OpHQh1XHGhpBRA%3D60G0oPTw%40mail.gmail.com.


--
Harlan Gilbert
Co-Chair and Math, Physics, Computer Science, and Philosophy Teacher
Green Meadow Waldorf High School
Chestnut Ridge, NY 10977

pri...@gmail.com

unread,
Jan 19, 2023, 11:36:42 AM1/19/23
to Glowscript Users
For b=14 the snippet below prints 1.6384e+4 1.6384e+4. Can I get 16384 instead?
And is there no way to handle more than 15 digits?

Web VPython 3.2
print_options(digits=15)
a=2
b=14
x1=pow(a,b)
x2=a**b
print(x1,x2)


Poul Riis

Bruce Sherwood

unread,
Jan 22, 2023, 2:32:55 PM1/22/23
to Glowscript Users
Here is the documentation on how to format text output:


15 digits is all that a "double" (64-bit) number can span.

Bruce
Reply all
Reply to author
Forward
0 new messages