Blame view

lib/math/lcm.c 482 Bytes
457c89965   Thomas Gleixner   treewide: Add SPD...
1
  // SPDX-License-Identifier: GPL-2.0-only
6016daed5   Rasmus Villemoes   lib/lcm.c: replac...
2
  #include <linux/compiler.h>
2cda2728a   Martin K. Petersen   block: Fix overru...
3
  #include <linux/gcd.h>
8bc3bcc93   Paul Gortmaker   lib: reduce the u...
4
  #include <linux/export.h>
72d39508e   H Hartley Sweeten   lib/lcm.c: quiet ...
5
  #include <linux/lcm.h>
2cda2728a   Martin K. Petersen   block: Fix overru...
6
7
8
9
10
  
  /* Lowest common multiple */
  unsigned long lcm(unsigned long a, unsigned long b)
  {
  	if (a && b)
74a5fef7c   Rasmus Villemoes   lib/lcm.c: ensure...
11
  		return (a / gcd(a, b)) * b;
69c953c85   Rasmus Villemoes   lib/lcm.c: lcm(n,...
12
13
  	else
  		return 0;
2cda2728a   Martin K. Petersen   block: Fix overru...
14
15
  }
  EXPORT_SYMBOL_GPL(lcm);
e9637415a   Mike Snitzer   block: fix blk_st...
16
17
18
19
20
21
22
23
24
25
26
  
  unsigned long lcm_not_zero(unsigned long a, unsigned long b)
  {
  	unsigned long l = lcm(a, b);
  
  	if (l)
  		return l;
  
  	return (b ? : a);
  }
  EXPORT_SYMBOL_GPL(lcm_not_zero);