TMathBase.cxx

Go to the documentation of this file.
00001 // @(#)root/base:$Id: TMathBase.cxx 20877 2007-11-19 11:17:07Z rdm $
00002 // Authors: Rene Brun 08/02/2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 // TMath Base functions                                                 //
00015 //                                                                      //
00016 // Define the functions Min, Max, Abs, Sign, Range for all types.       //
00017 // NB: These functions are unfortunately not available in a portable    //
00018 // way in std::.                                                        //
00019 //                                                                      //
00020 // More functions are defined in TMath.h. TMathBase.h is designed to be //
00021 // a stable file and used in place of TMath.h in the ROOT miniCore.     //
00022 //                                                                      //
00023 //////////////////////////////////////////////////////////////////////////
00024 
00025 #include "TMathBase.h"
00026 #include <math.h>
00027 
00028 //______________________________________________________________________________
00029 Long_t TMath::NextPrime(Long_t x)
00030 {
00031    // Return next prime number after x, unless x is a prime in which case
00032    // x is returned.
00033 
00034    if (x <= 2)
00035       return 2;
00036    if (x == 3)
00037       return 3;
00038 
00039    if (x % 2 == 0)
00040       x++;
00041 
00042    Long_t sqr = (Long_t) sqrt((Double_t)x) + 1;
00043 
00044    for (;;) {
00045       Long_t n;
00046       for (n = 3; (n <= sqr) && ((x % n) != 0); n += 2)
00047          ;
00048       if (n > sqr)
00049          return x;
00050       x += 2;
00051    }
00052 }

Generated on Tue Jul 5 14:11:21 2011 for ROOT_528-00b_version by  doxygen 1.5.1