Skip to content

Commit

Permalink
feat: Add rand function
Browse files Browse the repository at this point in the history
  • Loading branch information
NriotHrreion committed Sep 2, 2023
1 parent ef50052 commit 1e94362
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 40 deletions.
5 changes: 5 additions & 0 deletions src/components/MobileInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ const MobileInput: React.FC<MobileInputProps> = memo((props) => {
<InputButton symbol="\text{nCr}" inputValue="\text{nCr}(" grow={1}/>
<InputButton symbol="\text{Del}" grow={1}/>
</div>
<div className="keypad-row">
<InputButton symbol="\text{rand}" inputValue="\text{rand}(" grow={2}/>
<div style={{ flexGrow: 2 }}/>
<InputButton symbol="\text{Del}" grow={1}/>
</div>
</KeypadSection>
<KeypadSection id="professional">
<div className="keypad-row">
Expand Down
80 changes: 41 additions & 39 deletions src/global.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,46 @@ export const version = "1.3.0";
export const errorText = "\\text{Error}";

export const functions: Map<string, MathFunction> = new Map([
["sin", [(x) => Math.sin(x), 1]],
["cos", [(x) => Math.cos(x), 1]],
["tan", [(x) => Compute.safeTan(x), 1]],
["cot", [(x) => 1 / Compute.safeTan(x), 1]],
["sec", [(x) => 1 / Math.cos(x), 1]],
["csc", [(x) => 1 / Math.sin(x), 1]],
["sin^{-1}", [(x) => Math.asin(x), 1]],
["cos^{-1}", [(x) => Math.acos(x), 1]],
["tan^{-1}", [(x) => Math.atan(x), 1]],
["sinh", [(x) => Math.sinh(x), 1]],
["cosh", [(x) => Math.cosh(x), 1]],
["tanh", [(x) => Math.tanh(x), 1]],
["coth", [(x) => 1 / Math.tanh(x), 1]],
["text{sech}", [(x) => 1 / Math.cosh(x), 1]],
["text{csch}", [(x) => 1 / Math.sinh(x), 1]],
["ln", [(x) => Math.log(x), 1]],
["lg", [(x) => Math.log10(x), 1]],
["log_2", [(x) => Math.log2(x), 1]],
["deg", [(x) => x * (Math.PI / 180), 1]],
["text{rad}", [(x) => x * (180 / Math.PI), 1]],
["√", [(x) => Math.sqrt(x), 1]],
["^3√", [(x) => Math.cbrt(x), 1]],
["%", [(x) => x / 100, 1]],
["text{not}", [(x) => ~x, 1]],
["text{mean}", [(...n) => Compute.mean(...n), -1]],
["text{median}", [(...n) => Compute.median(...n), -1]],
["text{stdev}", [(...n) => Compute.stdev(...n), -1]],
["text{stdevp}", [(...n) => Compute.stdevp(...n), -1]],
["text{var}", [(...n) => Compute.safePow(Compute.stdev(...n), 2), -1]],
["text{count}", [(...n) => n.length, -1]],
["text{total}", [(...n) => Compute.total(...n), -1]],
["text{min}", [(...n) => Math.min(...n), -1]],
["text{max}", [(...n) => Math.max(...n), -1]],
["text{nPr}", [(n, r) => Compute.nPr(n, r), 2]],
["text{nCr}", [(n, r) => Compute.nCr(n, r), 2]],
["text{xPx}", [(x) => Compute.safePow(x, x), 1]],
["exp", [(x) => Compute.safePow(Math.E, x), 1]],
["text{floor}", [(x) => Math.floor(x), 1]],
["text{round}", [(x) => Math.round(x), 1]],
["sin", [(x) => Math.sin(x), 1]],
["cos", [(x) => Math.cos(x), 1]],
["tan", [(x) => Compute.safeTan(x), 1]],
["cot", [(x) => 1 / Compute.safeTan(x), 1]],
["sec", [(x) => 1 / Math.cos(x), 1]],
["csc", [(x) => 1 / Math.sin(x), 1]],
["sin^{-1}", [(x) => Math.asin(x), 1]],
["cos^{-1}", [(x) => Math.acos(x), 1]],
["tan^{-1}", [(x) => Math.atan(x), 1]],
["sinh", [(x) => Math.sinh(x), 1]],
["cosh", [(x) => Math.cosh(x), 1]],
["tanh", [(x) => Math.tanh(x), 1]],
["coth", [(x) => 1 / Math.tanh(x), 1]],
["text{sech}", [(x) => 1 / Math.cosh(x), 1]],
["text{csch}", [(x) => 1 / Math.sinh(x), 1]],
["ln", [(x) => Math.log(x), 1]],
["lg", [(x) => Math.log10(x), 1]],
["log_2", [(x) => Math.log2(x), 1]],
["deg", [(x) => x * (Math.PI / 180), 1]],
["text{rad}", [(x) => x * (180 / Math.PI), 1]],
["√", [(x) => Math.sqrt(x), 1]],
["^3√", [(x) => Math.cbrt(x), 1]],
["%", [(x) => x / 100, 1]],
["text{not}", [(x) => ~x, 1]],
["text{mean}", [(...n) => Compute.mean(...n), -1]],
["text{median}", [(...n) => Compute.median(...n), -1]],
["text{stdev}", [(...n) => Compute.stdev(...n), -1]],
["text{stdevp}", [(...n) => Compute.stdevp(...n), -1]],
["text{var}", [(...n) => Compute.safePow(Compute.stdev(...n), 2), -1]],
["text{count}", [(...n) => n.length, -1]],
["text{total}", [(...n) => Compute.total(...n), -1]],
["text{min}", [(...n) => Math.min(...n), -1]],
["text{max}", [(...n) => Math.max(...n), -1]],
["text{nPr}", [(n, r) => Compute.nPr(n, r), 2]],
["text{nCr}", [(n, r) => Compute.nCr(n, r), 2]],
["text{xPx}", [(x) => Compute.safePow(x, x), 1]],
["exp", [(x) => Compute.safePow(Math.E, x), 1]],
["text{floor}", [(x) => Math.floor(x), 1]],
["text{round}", [(x) => Math.round(x), 1]],
["text{rand}", [(a, b) => Math.floor(Math.random() * (b - a + 1) + a), 2]],
]);

export const constants: Map<string, number> = new Map([
Expand Down Expand Up @@ -112,6 +113,7 @@ export const acTable: Map<string, string> = new Map([
["exp", "\\exp("],
["floor", "\\text{floor}("],
["round", "\\text{round}("],
["rand", "\\text{rand}("],

["jini", "\\text{taimei}"],
]);
Expand Down
3 changes: 2 additions & 1 deletion src/views/general/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ const Input: React.FC = memo(() => {
<div style={{ flexGrow: 5 }}/>
</div>
<div className="keypad-row">
<div style={{ flexGrow: 5 }}/>
<InputButton symbol="\text{rand}" inputValue="\text{rand}(" grow={2}/>
<div style={{ flexGrow: 3 }}/>
<div className="keypad-placeholder"/>
<InputButton symbol="4" grow={1}/>
<InputButton symbol="5" grow={1}/>
Expand Down

1 comment on commit 1e94362

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.