Logo ROOT  
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\ingroup Base
14
15Define the functions Min, Max, Abs, Sign, Range for all types.
16NB: These functions are unfortunately not available in a portable
17way in std::.
18
19More functions are defined in TMath.h. TMathBase.h is designed to be
20a 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
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 Long_t
Definition: RtypesCore.h:50
double Double_t
Definition: RtypesCore.h:55
double sqrt(double)
Long_t NextPrime(Long_t x)
TMath Base functions.
Definition: TMathBase.cxx:30
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16
VecExpr< UnaryOp< Sqr< T >, VecExpr< A, T, D >, T >, T, D > sqr(const VecExpr< A, T, D > &rhs)