ROOT
6.06/09
Reference Guide
ROOT Home Page
Main Page
Related Pages
User's Classes
Namespaces
All Classes
Files
Release Notes
File List
File Members
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
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
29
Long_t
TMath::NextPrime
(
Long_t
x
)
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
}
sqrt
double sqrt(double)
x
Double_t x[n]
Definition:
legend1.C:17
TMathBase.h
Long_t
long Long_t
Definition:
RtypesCore.h:50
TMath::NextPrime
Long_t NextPrime(Long_t x)
TMath Base functions.
Definition:
TMathBase.cxx:29
Double_t
double Double_t
Definition:
RtypesCore.h:55
ROOT::Math::sqr
VecExpr< UnaryOp< Sqr< T >, VecExpr< A, T, D >, T >, T, D > sqr(const VecExpr< A, T, D > &rhs)
Definition:
UnaryOperators.h:208
n
const Int_t n
Definition:
legend1.C:16