Libraryless. Click here for Pure Java version (10166L/56K).
1 | persistable sclass PercentIncrease { |
2 | settable double percentIncrease; |
3 | |
4 | *(double *percentIncrease) {} |
5 | |
6 | double get() { ret percentIncrease; } |
7 | double asFactor aka factor aka getFactor() { ret 1+percentIncrease/100; } |
8 | |
9 | static PercentIncrease of(double percentIncrease) { |
10 | ret new PercentIncrease(percentIncrease); |
11 | } |
12 | |
13 | static PercentIncrease fromFactor(double factor) { |
14 | ret new PercentIncrease((factor-1)*100); |
15 | } |
16 | |
17 | toString { ret plusMinusFix(formatDouble_significant(percentIncrease, 4)) + "%"; } |
18 | |
19 | PercentIncrease combineWith aka mul(PercentIncrease i) { |
20 | ret fromFactor(asFactor()*i.asFactor()); |
21 | } |
22 | |
23 | double applyTo aka mul(double x) { |
24 | ret asFactor()*x; |
25 | } |
26 | |
27 | // gets the n-th root (an increase you can apply n times to get the original one) |
28 | PercentIncrease root aka nthRoot(double n) { |
29 | ret fromFactor(Math.pow(asFactor(), 1/n)); |
30 | } |
31 | |
32 | // gets the n-th power (an increase you can apply n times to get the original one) |
33 | PercentIncrease pow aka repeat(double n) { |
34 | ret fromFactor(Math.pow(asFactor(), n)); |
35 | } |
36 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): elmgxqgtpvxh, mowyntqkapby, mqqgnosmbjvj, wnsclhtenguj
No comments. add comment
Snippet ID: | #1036399 |
Snippet name: | PercentIncrease - object representing a certain percentual increase |
Eternal ID of this version: | #1036399/7 |
Text MD5: | 35540cb023d53ec5fa3d3c663c5b3e82 |
Transpilation MD5: | 042455cefcbd7fca014fa63a463796db |
Author: | stefan |
Category: | javax / gazelle 22 |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-12-08 00:26:20 |
Source code size: | 1106 bytes / 36 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 134 / 222 |
Version history: | 6 change(s) |
Referenced in: | [show references] |