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).

srecord Frequency(double frequency) is Comparable<Frequency> {
  gettable double interval;
  
  double frequency aka get() { ret frequency; }
  
  // !customConstructor
  *(double *frequency) { interval = doubleRatio(1, frequency); }
  
  toString { ret format3(); }
  
  S format3() { ret format(3); }
  S format1() { ret format(1); }
  
  S format(int digits) { ret str(new Rendering(digits)); }
  
  record noeq Rendering(int digits) {
    double value = frequency;
    S unit = "Hz";
    
    swappable S formatValue() { ret formatDouble(value, digits); }
    
    run {
      while (abs(value) >= 1000) {
        value /= 1000;
        unit = "k" + unit;
      }
      unit = replacePrefixes(unit,
        "kkkk", "T",
        "kkk", "G",
        "kk", "M");
    }
    
    toString { run(); ret spaceCombine(formatValue(), unit); }
  }
  
  public int compareTo(Frequency f) {
    ret cmp(frequency, f.frequency);
  }
}

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: 195 / 371
Version history: 13 change(s)
Referenced in: #1033101 - Seconds
#1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)