Skip to content

Commit

Permalink
Enhanced phi command
Browse files Browse the repository at this point in the history
- If something is on the stack, display the long and short results
- Regardless of stack, add the golden ratio to the top of the stack
- Updated the User Guide page to reflect this change
- Bumped the version of JUnit5 form 5.10.1 to 5.10.2
  • Loading branch information
frossm committed Feb 11, 2024
1 parent f551762 commit 58f9992
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
14 changes: 7 additions & 7 deletions mdbook/src/Chapters/Constants.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<img align="right" width="125" src="../Images/Constants.png">
<img alt="Page Icon" align="right" width="125" src="../Images/Constants.png">

# Constants

These commands simply take a defined constant and add that number to the top of the stack (`line1`). There are currently not that many constants defined, but if there is a desire to add additional ones please me know. It's quick and easy.

To use a constant, simply run the command and the value of the requested constant will be added to the top of the stack / `line1`

|Constant|Description|
|--------|-----------|
|pi|**PI - ARCHIMEDES' CONSTANT**<br>[Archimedes' constant, or PI](https://en.wikipedia.org/wiki/Pi), is the name given to the ratio of the circumference of a circle to the diameter. `PI` inserts the value of PI onto the stack. In RPNCalc, and Java in general, Pi is approximately `3.141592653589793`|
|phi|**PHI - THE GOLDEN RATIO**<br>Insert [PHI](https://en.wikipedia.org/wiki/Golden_ratio), also known as the Golden Ratio, to the stack. In RPNCalc, Phi is defined as `1.618033989`|
|euler|**EULER'S NUMBER**<br>Euler's number is also known as the exponential growth constant. It is the base for natural logarithms and is found in many areas of mathematics. The command `euler` inserts [Euler's number (e)](https://en.wikipedia.org/wiki/E_(mathematical_constant)) onto the stack. e is approximately `2.71828182845`|
|sol|**SPEED OF LIGHT**<br>Inserts the [speed of light](https://en.wikipedia.org/wiki/Speed_of_light), in meters per second, onto the stack in meters/second and is approximately `299,792,458 m/s`|
|Constant| Description |
|--------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|pi| **PI - ARCHIMEDES' CONSTANT**<br>[Archimedes' constant, or PI](https://en.wikipedia.org/wiki/Pi), is the name given to the ratio of the circumference of a circle to the diameter. `PI` inserts the value of PI onto the stack. In RPNCalc, and Java in general, Pi is approximately `3.141592653589793` |
|phi| **PHI - THE GOLDEN RATIO**<br>If the stack is empty, `phi` will simply insert the [PHI](https://en.wikipedia.org/wiki/Golden_ratio), also known as the Golden Ratio, onto the top of the stack (`line1`). In RPNCalc, Phi is defined as `1.618033989`<br>However, if there is an item on the stack, it will also display the possible long and short section values |
|euler| **EULER'S NUMBER**<br>Euler's number is also known as the exponential growth constant. It is the base for natural logarithms and is found in many areas of mathematics. The command `euler` inserts [Euler's number (e)](https://en.wikipedia.org/wiki/E_(mathematical_constant)) onto the stack. e is approximately `2.71828182845` |
|sol| **SPEED OF LIGHT**<br>Inserts the [speed of light](https://en.wikipedia.org/wiki/Speed_of_light), in meters per second, onto the stack in meters/second and is approximately `299,792,458 m/s` |
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.fross</groupId>
<artifactId>rpncalc</artifactId>
<version>5.2.0</version>
<version>5.2.1</version>
<packaging>jar</packaging>

<name>rpncalc</name>
Expand Down Expand Up @@ -247,7 +247,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.1</version>
<version>5.10.2</version>
<scope>test</scope>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: rpncalc
version: '5.2.0'
version: '5.2.1'
summary: The command line Reverse Polish Notation (RPN) calculator
description: |
RPNCalc is an easy to use command line based Reverse Polish
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/fross/rpncalc/CommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public static void Parse(StackObj calcStack, StackObj calcStack2, String cmdInpu
// Add PHI also known as The Golden Ratio
case "phi":
StackConstants.cmdPHI(calcStack);
Output.printColorln(Ansi.Color.CYAN, "Phi, the golden ratio, added to the stack");
Output.printColorln(Ansi.Color.CYAN, "Phi, the golden ratio, has been added to the stack");
break;

// Euler's number
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/org/fross/rpncalc/StackConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
* ------------------------------------------------------------------------------*/
package org.fross.rpncalc;

import org.fross.library.Output;
import org.fusesource.jansi.Ansi;

import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;

public class StackConstants {

/**
Expand All @@ -42,10 +49,22 @@ public static void cmdPI(StackObj calcStack) {
* cmdPHI(): Add the value PHI (Golden Ratio) to the stack
*/
public static void cmdPHI(StackObj calcStack) {
BigDecimal phi = new BigDecimal("1.61803398874989");
// Save current calcStack to the undoStack
calcStack.saveUndo();

calcStack.push("1.61803398874989");

// If there is something in the stack, display the long and short sections
if (!calcStack.isEmpty()) {
BigDecimal value = calcStack.peek();
Output.printColorln(Ansi.Color.YELLOW, "If Long Section = " + value + " Short Section = " + value.multiply(BigDecimal.ONE.divide(phi,
MathContext.DECIMAL128)).setScale(5, RoundingMode.HALF_UP));
Output.printColorln(Ansi.Color.YELLOW, "If Short Section = " + value + " Long Section = " + value.multiply(phi).setScale(5, RoundingMode.HALF_UP));
}

// Add the value of Phi to the top of the stack
calcStack.push(phi);

}

/**
Expand Down

0 comments on commit 58f9992

Please sign in to comment.