Post Reply 
[VA] SRC#002- Almost integers and other beasties
02-15-2019, 10:48 PM (This post was last modified: 02-16-2019 01:15 AM by Gerson W. Barbosa.)
Post: #33
RE: [VA] SRC#002- Almost integers and other beasties
(02-15-2019 06:50 PM)Albert Chan Wrote:  Can the sign flipping code be removed, and possibly gain some speed ?

Code:
>>> sum, k = 0, 35       # for 12 digits accuracy
>>> a = (1<<k) - 1       # k bits of 1
>>> while k > 0:
...     sum = 1/(a*k) - sum
...     a, k = a>>1, k-1
...
>>> print sum
0.868876652659

Oh, I see!

%%HP: T(3)A(R)F(.);
\<< RCLF SWAP -105 CF -3 CF DUP 1 + 'DIGITS' STO 10 LN * 2 LN SWAP DUP2 / LN + SWAP / CEIL 2 OVER ^ 1 - 0 ROT 1
  FOR i OVER i FMULT FINV SWAP FSUB SWAP 2 FDIV FIP SWAP -1
  STEP FSUB DUP FADD 2 FLN FDIV 12 FINV FADD FPI FSQ 6 FDIV 2 FLN FSQ FDIV FADD ZZ\<-\->F NEG SWAP \->STR DUP SIZE ROT \=/ -51 FC? { "." } { "," } IFTE UNROT { DUP TAIL SWAP HEAD } { "0" } IFTE UNROT + + DUP SIZE " " REPL " " "" SREPL DROP SWAP STOF
\>>


# 10B6h, 393.5 bytes

Now 129.59 seconds for 100 digits.

P.S.: Replaced NIP FNEG with FSUB at loop exit. I’d imagined the former were faster, but it turns our it’s actually 0.05 slower (although this is not conclusive after one measurement only).
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] SRC#002- Almost integers and other beasties - Gerson W. Barbosa - 02-15-2019 10:48 PM



User(s) browsing this thread: 1 Guest(s)