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

49
LINES

< > BotCompany Repo | #1001664 - max function

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

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

static int max(int a, int b) { ret Math.max(a, b); }
static int max(int a, int b, int c) { ret max(max(a, b), c); }
static long max(int a, long b) { ret Math.max((long) a, b); }
static long max(long a, long b) { ret Math.max(a, b); }
static double max(int a, double b) { ret Math.max((double) a, b); }
static float max(float a, float b) { ret Math.max(a, b); }
static double max(double a, double b) { ret Math.max(a, b); }

static int max(Collection<Integer> c) {
  int x = Integer.MIN_VALUE;
  for (int i : c) x = max(x, i);
  ret x;
}

static double max(double[] c) {
  if (c.length == 0) ret Double.MIN_VALUE;
  double x = c[0];
  for (int i = 1; i < c.length; i++) x = Math.max(x, c[i]);
  ret x;
}

static float max(float[] c) {
  if (c.length == 0) ret Float.MAX_VALUE;
  float x = c[0];
  for (int i = 1; i < c.length; i++) x = Math.max(x, c[i]);
  ret x;
}

static byte max(byte[] c) {
  byte x = -128;
  for (byte d : c) if (d > x) x = d;
  ret x;
}

static short max(short[] c) {
  short x = -0x8000;
  for (short d : c) if (d > x) x = d;
  ret x;
}

static int max(int[] c) {
  int x = Int.MIN_VALUE;
  for (int d : c) if (d > x) x = d;
  ret x;
}

static <A extends Comparable<A>> A max(A a, A b) {
  ret cmp(a, b) >= 0 ? a : b;
}

download  show line numbers  debug dex  old transpilations   

Travelled to 18 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, podlckwnjdmb, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, whxojlpjdney, xrpafgyirdlv

No comments. add comment

Snippet ID: #1001664
Snippet name: max function
Eternal ID of this version: #1001664/7
Text MD5: 16049adc9fc22937ed3190690a01423f
Transpilation MD5: 2961a5906109ab2ff51438066b51ed26
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-11-03 17:12:08
Source code size: 1290 bytes / 49 lines
Pitched / IR pitched: No / No
Views / Downloads: 672 / 5010
Version history: 6 change(s)
Referenced in: [show references]