Libraryless. Click here for Pure Java version (4033L/23K).
1 | sclass LowestDouble { |
2 | double best = Double.NaN; |
3 | transient O onChange; |
4 | |
5 | synchronized bool isNewBest(double d) { |
6 | ret isNaN(best) || d < best; |
7 | } |
8 | |
9 | // may return NaN |
10 | double get() { |
11 | ret best; |
12 | } |
13 | |
14 | bool put(double d) { |
15 | bool change; |
16 | synchronized(this) { |
17 | if (isNaN(best) || d < best) { |
18 | best = d; |
19 | set change; |
20 | } |
21 | } |
22 | if (change) |
23 | pcallF(onChange); |
24 | ret change; |
25 | } |
26 | |
27 | synchronized void clear() { best = Double.NaN; } |
28 | |
29 | synchronized bool has() { ret !isNaN(best); } |
30 | |
31 | synchronized toString { ret has() ? str(best) : "-"; } |
32 | } |
Began life as a copy of #1006448
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1032639 |
Snippet name: | LowestDouble - records the lowest double |
Eternal ID of this version: | #1032639/3 |
Text MD5: | 2ae3f68491eb9333d0aa6b79a4331295 |
Transpilation MD5: | e4536cd8e5bfdc2b5562d3318438dc29 |
Author: | stefan |
Category: | javax / genetic optimization |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-09-29 22:59:45 |
Source code size: | 626 bytes / 32 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 123 / 241 |
Version history: | 2 change(s) |
Referenced in: | [show references] |