Talk:Almkvist-Giullera formula for pi

Julia answer for Pi is wrong

After spending several minutes trying to figure out why my Wren entry was disagreeing with Julia, it turned out that the latter is wrong - Python, REXX and an independent source all agree on this - though, looking at the code, I couldn't see anything obviously wrong. --PureFox (talk) 10:56, 12 October 2020 (UTC)

Ah, it turns out setprecision() takes an argument in significant bits, not decimal digits! Thanks for the comment, fixed. --Wherrera (talk) 19:08, 12 October 2020 (UTC)

I wondered whether it might be something like that when I added the Go solution where you also have to estimate how many bits of precision you need for a given number of decimal places. Anyway, glad you've fixed it now :) --PureFox (talk) 20:47, 12 October 2020 (UTC)

Divide by zero error in big.wren; shouldn't there be a little more robust error-handling in the big.wren Library?

wren_cli ./almkvist_giullera_formula_for_pi.wren N Integer Portion Pow Nth Term (33 dp)

Cannot divide by zero. [../RC_Wren_Lib/big line 472] in divModAny_(_,_) [../RC_Wren_Lib/big line 1114] in /(_) [../RC_Wren_Lib/big line 628] in gcd(_,_) [../RC_Wren_Lib/big line 1727] in init new(_,_) [../RC_Wren_Lib/big line 1734] in [./almkvist_giullera_formula_for_pi line 17] in new(_) block argument [./almkvist_giullera_formula_for_pi line 28] in (script)

Thanks, Retired_Build_Engineer

I'm puzzled by this error since, when I run the example (as posted) on my own machine, there's no error and the output is as expected.
Are you perhaps trying to run a modified version?
As far as error handling is concerned in Wren-big, a division by zero error is generally unrecoverable as there is no infinity support for big integers like there is with floating-point. So that's why I've chosen to abort the fiber in line 472. If you were writing an application where you couldn't tolerate the script ending prematurely, then you'd need to run the code in a separate fiber using Fiber.try() and thereby catch any error to give you the opportunity of handling it more gracefully. Note that Wren doesn't support exceptions as such. --PureFox (talk) 08:19, 2 September 2023 (UTC)
Return to "Almkvist-Giullera formula for pi" page.