Libraryless. Click here for Pure Java version (10166L/56K).
persistable sclass PercentIncrease { settable double percentIncrease; *(double *percentIncrease) {} double get() { ret percentIncrease; } double asFactor aka factor aka getFactor() { ret 1+percentIncrease/100; } static PercentIncrease of(double percentIncrease) { ret new PercentIncrease(percentIncrease); } static PercentIncrease fromFactor(double factor) { ret new PercentIncrease((factor-1)*100); } toString { ret plusMinusFix(formatDouble_significant(percentIncrease, 4)) + "%"; } PercentIncrease combineWith aka mul(PercentIncrease i) { ret fromFactor(asFactor()*i.asFactor()); } double applyTo aka mul(double x) { ret asFactor()*x; } // gets the n-th root (an increase you can apply n times to get the original one) PercentIncrease root aka nthRoot(double n) { ret fromFactor(Math.pow(asFactor(), 1/n)); } // gets the n-th power (an increase you can apply n times to get the original one) PercentIncrease pow aka repeat(double n) { ret fromFactor(Math.pow(asFactor(), n)); } }
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: | 132 / 220 |
Version history: | 6 change(s) |
Referenced in: | [show references] |