Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

39
LINES

< > BotCompany Repo | #1032953 // Frequency

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (10925L/62K).

1  
srecord Frequency(double frequency) is Comparable<Frequency> {
2  
  gettable double interval;
3  
  
4  
  double frequency aka get() { ret frequency; }
5  
  
6  
  // !customConstructor
7  
  *(double *frequency) { interval = doubleRatio(1, frequency); }
8  
  
9  
  toString { ret format3(); }
10  
  
11  
  S format3() { ret format(3); }
12  
  S format1() { ret format(1); }
13  
  
14  
  S format(int digits) { ret str(new Rendering(digits)); }
15  
  
16  
  record noeq Rendering(int digits) {
17  
    double value = frequency;
18  
    S unit = "Hz";
19  
    
20  
    swappable S formatValue() { ret formatDouble(value, digits); }
21  
    
22  
    run {
23  
      while (abs(value) >= 1000) {
24  
        value /= 1000;
25  
        unit = "k" + unit;
26  
      }
27  
      unit = replacePrefixes(unit,
28  
        "kkkk", "T",
29  
        "kkk", "G",
30  
        "kk", "M");
31  
    }
32  
    
33  
    toString { run(); ret spaceCombine(formatValue(), unit); }
34  
  }
35  
  
36  
  public int compareTo(Frequency f) {
37  
    ret cmp(frequency, f.frequency);
38  
  }
39  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1032953
Snippet name: Frequency
Eternal ID of this version: #1032953/14
Text MD5: dd800e1041b7af342cbae09407656192
Transpilation MD5: 33a86bd5045844663c47c972b624705f
Author: stefan
Category: javax / stefan's os
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-05-07 01:53:07
Source code size: 963 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 196 / 372
Version history: 13 change(s)
Referenced in: [show references]