Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
howto:calculate-dc [2015/08/09 05:50]
bill_thomson
howto:calculate-dc [2017/01/02 08:25] (current)
gerbehar [Conditionals and Loops] typo corrected
Line 59: Line 59:
  
 ''​dc''​ is a calulator with abitrary precision, by default this precision is 0.  ''​dc''​ is a calulator with abitrary precision, by default this precision is 0. 
-thus ''​dc <<<​ "5 4/​p"''​ prints "​1"​.+thus ''​<​nowiki>​dc <<<​ "5 4/p"</​nowiki>​''​ prints "​1"​.
  
 We can increase the precision using the ''​k''​ command. It pops the value at the top of the stack We can increase the precision using the ''​k''​ command. It pops the value at the top of the stack
Line 226: Line 226:
 </​code>​ </​code>​
  
-Some ''​dc''​ have ''>​R <R =R'',​ GNU ''​dc''​ had some more, check your manual. ​Not +Some ''​dc''​ have ''>​R <R =R'',​ GNU ''​dc''​ had some more, check your manual. ​Note 
-that the test "​consumes"​ its operands the 2 first elements are popped+that the test "​consumes"​ its operandsthe 2 first elements are popped
 off the stack (you can verify that ''​dc <<<​ "[f]sR 2 1 >R 1 2 >R f"''​ off the stack (you can verify that ''​dc <<<​ "[f]sR 2 1 >R 1 2 >R f"''​
 doesn'​t print anything) doesn'​t print anything)
Line 252: Line 252:
   1 -      # we decrement the index by one   1 -      # we decrement the index by one
   si    # store decremented index (i=i-1)   si    # store decremented index (i=i-1)
- 0 li >L   # if i > 0 the execute L+ 0 li >L   # if i > 0 then execute L
 ] sL       # store our macro with the name L ] sL       # store our macro with the name L