ROOT  6.06/09
Reference Guide
TMathBase.cxx
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Authors: Rene Brun 08/02/2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /** TMath Base functions
13 
14 Define the functions Min, Max, Abs, Sign, Range for all types.
15 NB: These functions are unfortunately not available in a portable
16 way in std::.
17 
18 More functions are defined in TMath.h. TMathBase.h is designed to be
19 a stable file and used in place of TMath.h in the ROOT miniCore.
20 */
21 
22 #include "TMathBase.h"
23 #include <math.h>
24 
25 ////////////////////////////////////////////////////////////////////////////////
26 /// Return next prime number after x, unless x is a prime in which case
27 /// x is returned.
28 
30 {
31  if (x <= 2)
32  return 2;
33  if (x == 3)
34  return 3;
35 
36  if (x % 2 == 0)
37  x++;
38 
39  Long_t sqr = (Long_t) sqrt((Double_t)x) + 1;
40 
41  for (;;) {
42  Long_t n;
43  for (n = 3; (n <= sqr) && ((x % n) != 0); n += 2)
44  ;
45  if (n > sqr)
46  return x;
47  x += 2;
48  }
49 }
double sqrt(double)
Double_t x[n]
Definition: legend1.C:17
long Long_t
Definition: RtypesCore.h:50
Long_t NextPrime(Long_t x)
TMath Base functions.
Definition: TMathBase.cxx:29
double Double_t
Definition: RtypesCore.h:55
VecExpr< UnaryOp< Sqr< T >, VecExpr< A, T, D >, T >, T, D > sqr(const VecExpr< A, T, D > &rhs)
const Int_t n
Definition: legend1.C:16