ROOT
6.18/05
Reference Guide
core
base
src
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
\ingroup Base
14
15
Define the functions Min, Max, Abs, Sign, Range for all types.
16
NB: These functions are unfortunately not available in a portable
17
way in std::.
18
19
More functions are defined in TMath.h. TMathBase.h is designed to be
20
a stable file and used in place of TMath.h in the ROOT miniCore.
21
*/
22
23
#include "
TMathBase.h
"
24
#include <math.h>
25
26
////////////////////////////////////////////////////////////////////////////////
27
/// Return next prime number after x, unless x is a prime in which case
28
/// x is returned.
29
30
Long_t
TMath::NextPrime
(
Long_t
x
)
31
{
32
if
(
x
<= 2)
33
return
2;
34
if
(
x
== 3)
35
return
3;
36
37
if
(
x
% 2 == 0)
38
x
++;
39
40
Long_t
sqr
= (
Long_t
)
sqrt
((
Double_t
)
x
) + 1;
41
42
for
(;;) {
43
Long_t
n
;
44
for
(
n
= 3; (
n
<=
sqr
) && ((
x
%
n
) != 0);
n
+= 2)
45
;
46
if
(
n
>
sqr
)
47
return
x
;
48
x
+= 2;
49
}
50
}
Long_t
long Long_t
Definition:
RtypesCore.h:50
Double_t
double Double_t
Definition:
RtypesCore.h:55
TMathBase.h
sqrt
double sqrt(double)
TMath::NextPrime
Long_t NextPrime(Long_t x)
TMath Base functions.
Definition:
TMathBase.cxx:30
x
Double_t x[n]
Definition:
legend1.C:17
n
const Int_t n
Definition:
legend1.C:16
ROOT::Math::sqr
VecExpr< UnaryOp< Sqr< T >, VecExpr< A, T, D >, T >, T, D > sqr(const VecExpr< A, T, D > &rhs)
Definition:
UnaryOperators.h:206