Skip to main content
added 6 characters in body
Source Link

The program should now workswork for arbitrarily large numbers, restricted only by the memory capacity of the computer.

The program now works for arbitrarily large numbers, restricted only by the memory capacity of the computer.

The program should now work for arbitrarily large numbers, restricted only by the memory capacity of the computer.

added 147 characters in body
Source Link

Or verify the test suite: the OP's test cases, 2147483647, and a very large Lucas number (over 400 trillion) which comes out neatly in base \$\varphi\$ (see screenshot below for that last test case by itself).

Had to add a few bytes to handle very large input values correctly.

The program now works for arbitrarily large numbers, restricted only by the memory capacity of the computer.

Sample run on a very large Lucas number

Or verify the test suite: the OP's test cases, 2147483647, and a very large Lucas number (over 400 trillion) which comes out neatly in base \$\varphi\$.

Had to add a few bytes to handle very large input values correctly.

The program now works for arbitrarily large numbers, restricted only by the memory capacity of the computer.

Or verify the test suite: the OP's test cases, 2147483647, and a very large Lucas number (over 400 trillion) which comes out neatly in base \$\varphi\$ (see screenshot below for that last test case by itself).

The program now works for arbitrarily large numbers, restricted only by the memory capacity of the computer.

Sample run on a very large Lucas number

added 563 characters in body
Source Link

dc, 107 106 110107 106 110 109 bytes

FFk[0sD]sZ0ddsRsK[0sD]sZ0ddsRsK?dsXZ5*dsNdsXZF*dkdsN-sM[lX5v1dsD+2/lN^dsY>ZlXlDlY*-sXlDdAlN^*lR+sRlKdlN+lD*-sKlN1-dsNlM!>L]dsLxlRlKk1/p 

Try it online!Try it online!

Or verify all the test cases (including 2147483647)verify the test suite: the OP's test cases, 2147483647, and a very large Lucas number (over 400 trillion) which comes out neatly in base \$\varphi\$.

The program now works for arbitrarily large numbers, restricted only by the memory capacity of the computer.

How it works:

FFk Set precision to 99 or 165 decimal places, depending on the version of dc used. On TIO, it's 165. [0sD]sZ Macro Z, sets D to 0 when called. 0ddsRsK  Initialize R and K to 0, leaving 0 on the stack. ?dsXZ5*sNdsX  Input number, store it in X, Z5*dsN ZF*dkdsN store 515 times its number of decimal digits in N, also set that as the number of decimal places for computations, -sM and store the negative of that in M. M and N are bounds on the powers of phi which will be needed for the representation. Multiplying by 15 is far more than is needed: For M and N, becausewe could have multiplied by just 5,   because ln(10)/ln(phi) < 5. We need some additional decimal places in the computations to handle possible round-off errors, so we conservatively multiply by 15. [ Start a macro (which will be used as a loop). lX Push X onto the stack. 5v1dsD+2/lN^ Set D=1. Compute phi^N, dsY and store it in Y. >Z If phi^N > X, use macro Z to set D=0. lXlDlY*-sX If D is 1, set X = X - phi^N. lDdAlN^*lR+sR R += D * 10^N. This places the digit D in R in the right position, treating R as a number in base 10. lKdlN+lD*-sK If D is 1, set K = -N. (K is used as the number of "decimal" places to print.) lN1-dsN Set N = N-1, leaving the new value of N at the top of the stack. lM!>L If M <= N, call macro L recursively (in other words, start another loop iteration). ] End the macro, dsL save it in register L, x and execute it. Once the loop is done: lR Load the result R. lKk Set the precision (number of decimal places) to K. 1/ Divide R by 1 to convert it to the desired precision. p Print it. 

dc, 107 106 110 bytes

FFk[0sD]sZ0ddsRsK?dsXZ5*dsN-sM[lX5v1dsD+2/lN^dsY>ZlXlDlY*-sXlDdAlN^*lR+sRlKdlN+lD*-sKlN1-dsNlM!>L]dsLxlRlKk1/p 

Try it online!

Or verify all the test cases (including 2147483647).

How it works:

FFk Set precision to 99 or 165 decimal places, depending on the version of dc used. On TIO, it's 165. [0sD]sZ Macro Z, sets D to 0 when called. 0ddsRsK  Initialize R and K to 0, leaving 0 on the stack. ?dsXZ5*sN Input number, store it in X, Z5*dsN  store 5 times its number of decimal digits in N, -sM and store the negative of that in M. M and N are bounds on the powers of phi which will be needed for the representation, because ln(10)/ln(phi) < 5. [ Start a macro (which will be used as a loop). lX Push X onto the stack. 5v1dsD+2/lN^ Set D=1. Compute phi^N, dsY and store it in Y. >Z If phi^N > X, use macro Z to set D=0. lXlDlY*-sX If D is 1, set X = X - phi^N. lDdAlN^*lR+sR R += D * 10^N. This places the digit D in R in the right position, treating R as a number in base 10. lKdlN+lD*-sK If D is 1, set K = -N. (K is used as the number of "decimal" places to print.) lN1-dsN Set N = N-1, leaving the new value of N at the top of the stack. lM!>L If M <= N, call macro L recursively (in other words, start another loop iteration). ] End the macro, dsL save it in register L, x and execute it. Once the loop is done: lR Load the result R. lKk Set the precision (number of decimal places) to K. 1/ Divide R by 1 to convert it to the desired precision. p Print it. 

dc, 107 106 110 109 bytes

[0sD]sZ0ddsRsK?dsXZF*dkdsN-sM[lX5v1dsD+2/lN^dsY>ZlXlDlY*-sXlDdAlN^*lR+sRlKdlN+lD*-sKlN1-dsNlM!>L]dsLxlRlKk1/p 

Try it online!

Or verify the test suite: the OP's test cases, 2147483647, and a very large Lucas number (over 400 trillion) which comes out neatly in base \$\varphi\$.

The program now works for arbitrarily large numbers, restricted only by the memory capacity of the computer.

How it works:

[0sD]sZ Macro Z, sets D to 0 when called. 0ddsRsK Initialize R and K to 0, leaving 0 on the stack. ?dsX  Input number, store it in X, ZF*dkdsN store 15 times its number of decimal digits in N, also set that as the number of decimal places for computations, -sM and store the negative of that in M. M and N are bounds on the powers of phi which will be needed for the representation. Multiplying by 15 is far more than is needed: For M and N, we could have multiplied by just 5,   because ln(10)/ln(phi) < 5. We need some additional decimal places in the computations to handle possible round-off errors, so we conservatively multiply by 15. [ Start a macro (which will be used as a loop). lX Push X onto the stack. 5v1dsD+2/lN^ Set D=1. Compute phi^N, dsY and store it in Y. >Z If phi^N > X, use macro Z to set D=0. lXlDlY*-sX If D is 1, set X = X - phi^N. lDdAlN^*lR+sR R += D * 10^N. This places the digit D in R in the right position, treating R as a number in base 10. lKdlN+lD*-sK If D is 1, set K = -N. (K is used as the number of "decimal" places to print.) lN1-dsN Set N = N-1, leaving the new value of N at the top of the stack. lM!>L If M <= N, call macro L recursively (in other words, start another loop iteration). ] End the macro, dsL save it in register L, x and execute it. Once the loop is done: lR Load the result R. lKk Set the precision (number of decimal places) to K. 1/ Divide R by 1 to convert it to the desired precision. p Print it. 
added 81 characters in body
Source Link
Loading
added 2 characters in body
Source Link
Loading
added 43 characters in body
Source Link
Loading
added 23 characters in body
Source Link
Loading
added 372 characters in body
Source Link
Loading
deleted 2 characters in body
Source Link
Loading
edited body
Source Link
Loading
added 1 character in body
Source Link
Loading
added 1444 characters in body
Source Link
Loading
added 1444 characters in body
Source Link
Loading
Source Link
Loading