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

48
LINES

< > BotCompany Repo | #1001796 // min function

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

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

1  
static int min(int a, int b) {
2  
  ret Math.min(a, b);
3  
}
4  
5  
static long min(long a, long b) {
6  
  ret Math.min(a, b);
7  
}
8  
9  
static float min(float a, float b) { ret Math.min(a, b); }
10  
static float min(float a, float b, float c) { ret min(min(a, b), c); }
11  
12  
static double min(double a, double b) {
13  
  ret Math.min(a, b);
14  
}
15  
16  
static double min(double[] c) {
17  
  double x = Double.MAX_VALUE;
18  
  for (double d : c) x = Math.min(x, d);
19  
  ret x;
20  
}
21  
22  
static float min(float[] c) {
23  
  float x = Float.MAX_VALUE;
24  
  for (float d : c) x = Math.min(x, d);
25  
  ret x;
26  
}
27  
28  
static byte min(byte[] c) {
29  
  byte x = 127;
30  
  for (byte d : c) if (d < x) x = d;
31  
  ret x;
32  
}
33  
34  
static short min(short[] c) {
35  
  short x = 0x7FFF;
36  
  for (short d : c) if (d < x) x = d;
37  
  ret x;
38  
}
39  
40  
static int min(int[] c) {
41  
  int x = Int.MAX_VALUE;
42  
  for (int d : c) if (d < x) x = d;
43  
  ret x;
44  
}
45  
46  
static <A extends Comparable<A>> A min(A a, A b) {
47  
  ret cmp(a, b) <= 0 ? a : b;
48  
}

Author comment

Began life as a copy of #1001664

download  show line numbers  debug dex  old transpilations   

Travelled to 20 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, ekrmjmnbrukm, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, uelavcdoioby, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1001796
Snippet name: min function
Eternal ID of this version: #1001796/4
Text MD5: cad25230c3ef70b711f299e975dfcdf4
Transpilation MD5: b2f25d1d707d5c517303ec815bfbff73
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-12-20 22:18:12
Source code size: 959 bytes / 48 lines
Pitched / IR pitched: No / No
Views / Downloads: 833 / 5164
Version history: 3 change(s)
Referenced in: [show references]