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

6
LINES

< > BotCompany Repo | #1031996 // closestDoubleKey - floorKey or ceilingKey depending on numeric distance. double as in float

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

Libraryless. Click here for Pure Java version (38L/1K).

static Double closestDoubleKey(NavigableMap<Double, ?> map, double key) {
  Double a = map.floorKey(key), b = map.ceilingKey(key);
  if (b == null) ret a;
  if (a == null) ret b;
  ret abs(a-key) <= abs(b-key) ? a : b;
}

Author comment

Began life as a copy of #1008021

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx

No comments. add comment

Snippet ID: #1031996
Snippet name: closestDoubleKey - floorKey or ceilingKey depending on numeric distance. double as in float
Eternal ID of this version: #1031996/2
Text MD5: f5eb9cfd5f5f8312c9ef8f671346d734
Transpilation MD5: a8750aaad4299f8c7b6b75cef479edf1
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-08-08 15:11:32
Source code size: 225 bytes / 6 lines
Pitched / IR pitched: No / No
Views / Downloads: 83 / 132
Version history: 1 change(s)
Referenced in: [show references]