Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions hist/hist/inc/TH1.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

#include <algorithm>
#include <cfloat>
#include <limits>
#include <string>
#include <stdexcept>
#include <type_traits>
Expand Down Expand Up @@ -556,11 +557,11 @@ class TH1 : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
virtual Int_t GetDimension() const { return fDimension; }
virtual Double_t GetKurtosis(Int_t axis=1) const;
virtual void GetLowEdge(Double_t *edge) const;
virtual Double_t GetMaximum(Double_t maxval=FLT_MAX) const;
virtual Double_t GetMaximum(Double_t maxval = std::numeric_limits<float>::max()) const;
virtual Int_t GetMaximumBin() const;
virtual Int_t GetMaximumBin(Int_t &locmax, Int_t &locmay, Int_t &locmaz) const;
virtual Double_t GetMaximumStored() const {return fMaximum;}
virtual Double_t GetMinimum(Double_t minval=-FLT_MAX) const;
virtual Double_t GetMinimum(Double_t minval = -std::numeric_limits<float>::max()) const;
virtual Int_t GetMinimumBin() const;
virtual Int_t GetMinimumBin(Int_t &locmix, Int_t &locmiy, Int_t &locmiz) const;
virtual Double_t GetMinimumStored() const {return fMinimum;}
Expand Down
36 changes: 24 additions & 12 deletions hist/hist/src/TH1.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8791,7 +8791,7 @@ Double_t TH1::GetMaximum(Double_t maxval) const
Int_t ylast = fYaxis.GetLast();
Int_t zfirst = fZaxis.GetFirst();
Int_t zlast = fZaxis.GetLast();
Double_t maximum = -FLT_MAX, value;
Double_t maximum = -std::numeric_limits<float>::max(), value;
for (binz=zfirst;binz<=zlast;binz++) {
for (biny=yfirst;biny<=ylast;biny++) {
for (binx=xfirst;binx<=xlast;binx++) {
Expand Down Expand Up @@ -8831,7 +8831,7 @@ Int_t TH1::GetMaximumBin(Int_t &locmax, Int_t &locmay, Int_t &locmaz) const
Int_t ylast = fYaxis.GetLast();
Int_t zfirst = fZaxis.GetFirst();
Int_t zlast = fZaxis.GetLast();
Double_t maximum = -FLT_MAX, value;
Double_t maximum = -std::numeric_limits<float>::max(), value;
locm = locmax = locmay = locmaz = 0;
for (binz=zfirst;binz<=zlast;binz++) {
for (biny=yfirst;biny<=ylast;biny++) {
Expand Down Expand Up @@ -8881,7 +8881,7 @@ Double_t TH1::GetMinimum(Double_t minval) const
Int_t ylast = fYaxis.GetLast();
Int_t zfirst = fZaxis.GetFirst();
Int_t zlast = fZaxis.GetLast();
Double_t minimum=FLT_MAX, value;
Double_t minimum = std::numeric_limits<float>::max(), value;
for (binz=zfirst;binz<=zlast;binz++) {
for (biny=yfirst;biny<=ylast;biny++) {
for (binx=xfirst;binx<=xlast;binx++) {
Expand Down Expand Up @@ -8919,7 +8919,7 @@ Int_t TH1::GetMinimumBin(Int_t &locmix, Int_t &locmiy, Int_t &locmiz) const
Int_t ylast = fYaxis.GetLast();
Int_t zfirst = fZaxis.GetFirst();
Int_t zlast = fZaxis.GetLast();
Double_t minimum = FLT_MAX, value;
Double_t minimum = std::numeric_limits<float>::max(), value;
locm = locmix = locmiy = locmiz = 0;
for (binz=zfirst;binz<=zlast;binz++) {
for (biny=yfirst;biny<=ylast;biny++) {
Expand Down Expand Up @@ -10120,7 +10120,8 @@ TH1I::TH1I(const TH1I &h1i) : TH1(), TArrayI()

void TH1I::AddBinContent(Int_t bin)
{
if (fArray[bin] < INT_MAX) fArray[bin]++;
if (fArray[bin] < std::numeric_limits<int>::max())
fArray[bin]++;
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -10131,9 +10132,14 @@ void TH1I::AddBinContent(Int_t bin)
void TH1I::AddBinContent(Int_t bin, Double_t w)
{
Long64_t newval = fArray[bin] + Long64_t(w);
if (newval > -INT_MAX && newval < INT_MAX) {fArray[bin] = Int_t(newval); return;}
if (newval < -INT_MAX) fArray[bin] = -INT_MAX;
if (newval > INT_MAX) fArray[bin] = INT_MAX;
if (newval > -std::numeric_limits<int>::max() && newval < std::numeric_limits<int>::max()) {
fArray[bin] = Int_t(newval);
return;
}
if (newval < -std::numeric_limits<int>::max())
fArray[bin] = -std::numeric_limits<int>::max();
if (newval > std::numeric_limits<int>::max())
fArray[bin] = std::numeric_limits<int>::max();
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -10307,7 +10313,8 @@ TH1L::TH1L(const TH1L &h1l) : TH1(), TArrayL64()

void TH1L::AddBinContent(Int_t bin)
{
if (fArray[bin] < LLONG_MAX) fArray[bin]++;
if (fArray[bin] < std::numeric_limits<long long>::max())
fArray[bin]++;
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -10318,9 +10325,14 @@ void TH1L::AddBinContent(Int_t bin)
void TH1L::AddBinContent(Int_t bin, Double_t w)
{
Long64_t newval = fArray[bin] + Long64_t(w);
if (newval > -LLONG_MAX && newval < LLONG_MAX) {fArray[bin] = newval; return;}
if (newval < -LLONG_MAX) fArray[bin] = -LLONG_MAX;
if (newval > LLONG_MAX) fArray[bin] = LLONG_MAX;
if (newval > -std::numeric_limits<long long>::max() && newval < std::numeric_limits<long long>::max()) {
fArray[bin] = newval;
return;
}
if (newval < -std::numeric_limits<long long>::max())
fArray[bin] = -std::numeric_limits<long long>::max();
if (newval > std::numeric_limits<long long>::max())
fArray[bin] = std::numeric_limits<long long>::max();
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
29 changes: 21 additions & 8 deletions hist/hist/src/TH2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "TVirtualHistPainter.h"

#include <cstdio>
#include <limits>

#include "Rebin2DHelpers.h"

Expand Down Expand Up @@ -3450,7 +3451,8 @@ TH2I::TH2I(const TH2I &h2i) : TH2(), TArrayI()

void TH2I::AddBinContent(Int_t bin)
{
if (fArray[bin] < INT_MAX) fArray[bin]++;
if (fArray[bin] < std::numeric_limits<int>::max())
fArray[bin]++;
}


Expand All @@ -3462,9 +3464,14 @@ void TH2I::AddBinContent(Int_t bin)
void TH2I::AddBinContent(Int_t bin, Double_t w)
{
Long64_t newval = fArray[bin] + Long64_t(w);
if (newval > -INT_MAX && newval < INT_MAX) {fArray[bin] = Int_t(newval); return;}
if (newval < -INT_MAX) fArray[bin] = -INT_MAX;
if (newval > INT_MAX) fArray[bin] = INT_MAX;
if (newval > -std::numeric_limits<int>::max() && newval < std::numeric_limits<int>::max()) {
fArray[bin] = Int_t(newval);
return;
}
if (newval < -std::numeric_limits<int>::max())
fArray[bin] = -std::numeric_limits<int>::max();
if (newval > std::numeric_limits<int>::max())
fArray[bin] = std::numeric_limits<int>::max();
}


Expand Down Expand Up @@ -3678,7 +3685,8 @@ TH2L::TH2L(const TH2L &h2l) : TH2(), TArrayL64()

void TH2L::AddBinContent(Int_t bin)
{
if (fArray[bin] < LLONG_MAX) fArray[bin]++;
if (fArray[bin] < std::numeric_limits<long long>::max())
fArray[bin]++;
}


Expand All @@ -3690,9 +3698,14 @@ void TH2L::AddBinContent(Int_t bin)
void TH2L::AddBinContent(Int_t bin, Double_t w)
{
Long64_t newval = fArray[bin] + Long64_t(w);
if (newval > -LLONG_MAX && newval < LLONG_MAX) {fArray[bin] = newval; return;}
if (newval < -LLONG_MAX) fArray[bin] = -LLONG_MAX;
if (newval > LLONG_MAX) fArray[bin] = LLONG_MAX;
if (newval > -std::numeric_limits<long long>::max() && newval < std::numeric_limits<long long>::max()) {
fArray[bin] = newval;
return;
}
if (newval < -std::numeric_limits<long long>::max())
fArray[bin] = -std::numeric_limits<long long>::max();
if (newval > std::numeric_limits<long long>::max())
fArray[bin] = std::numeric_limits<long long>::max();
}


Expand Down
29 changes: 21 additions & 8 deletions hist/hist/src/TH3.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <algorithm>
#include <atomic>
#include <limits>
#include <stdexcept>


Expand Down Expand Up @@ -4167,7 +4168,8 @@ TH3I::TH3I(const TH3I &h3i) : TH3(), TArrayI()

void TH3I::AddBinContent(Int_t bin)
{
if (fArray[bin] < INT_MAX) fArray[bin]++;
if (fArray[bin] < std::numeric_limits<int>::max())
fArray[bin]++;
}


Expand All @@ -4179,9 +4181,14 @@ void TH3I::AddBinContent(Int_t bin)
void TH3I::AddBinContent(Int_t bin, Double_t w)
{
Long64_t newval = fArray[bin] + Long64_t(w);
if (newval > -INT_MAX && newval < INT_MAX) {fArray[bin] = Int_t(newval); return;}
if (newval < -INT_MAX) fArray[bin] = -INT_MAX;
if (newval > INT_MAX) fArray[bin] = INT_MAX;
if (newval > -std::numeric_limits<int>::max() && newval < std::numeric_limits<int>::max()) {
fArray[bin] = Int_t(newval);
return;
}
if (newval < -std::numeric_limits<int>::max())
fArray[bin] = -std::numeric_limits<int>::max();
if (newval > std::numeric_limits<int>::max())
fArray[bin] = std::numeric_limits<int>::max();
}


Expand Down Expand Up @@ -4373,7 +4380,8 @@ TH3L::TH3L(const TH3L &h3l) : TH3(), TArrayL64()

void TH3L::AddBinContent(Int_t bin)
{
if (fArray[bin] < LLONG_MAX) fArray[bin]++;
if (fArray[bin] < std::numeric_limits<long long>::max())
fArray[bin]++;
}


Expand All @@ -4385,9 +4393,14 @@ void TH3L::AddBinContent(Int_t bin)
void TH3L::AddBinContent(Int_t bin, Double_t w)
{
Long64_t newval = fArray[bin] + Long64_t(w);
if (newval > -LLONG_MAX && newval < LLONG_MAX) {fArray[bin] = newval; return;}
if (newval < -LLONG_MAX) fArray[bin] = -LLONG_MAX;
if (newval > LLONG_MAX) fArray[bin] = LLONG_MAX;
if (newval > -std::numeric_limits<long long>::max() && newval < std::numeric_limits<long long>::max()) {
fArray[bin] = newval;
return;
}
if (newval < -std::numeric_limits<long long>::max())
fArray[bin] = -std::numeric_limits<long long>::max();
if (newval > std::numeric_limits<long long>::max())
fArray[bin] = std::numeric_limits<long long>::max();
}


Expand Down
4 changes: 3 additions & 1 deletion hist/hist/src/THLimitsFinder.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "THLimitsFinder.h"

#include <algorithm>
#include <limits>

THLimitsFinder *THLimitsFinder::fgLimitsFinder = nullptr;

Expand Down Expand Up @@ -222,7 +223,8 @@ void THLimitsFinder::Optimize(Double_t A1, Double_t A2, Int_t nold ,
L20:
awidth = (ah-al)/Double_t(ntemp);
timemulti = 1;
if (awidth >= FLT_MAX) goto LOK; //in float.h
if (awidth >= std::numeric_limits<float>::max())
goto LOK;
if (awidth <= 0) goto LOK;

// If time representation, bin width should be rounded to seconds
Expand Down
4 changes: 3 additions & 1 deletion hist/spectrumpainter/src/TSpectrum2Painter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Pysica Slovaca Vol. 54/ 4 (2004), pp. 385-400.
*/

#include <climits>
#include <limits>

#include "TROOT.h"
#include "TColor.h"
Expand Down Expand Up @@ -488,7 +489,8 @@ void TSpectrum2Painter::ColorModel(unsigned ui, unsigned ui1, unsigned ui2,
a = fRainbow1Step;
a = ui*a;
a = ui1+a;
if (a >= UINT_MAX) uinc1 = UINT_MAX;
if (a >= std::numeric_limits<unsigned>::max())
uinc1 = std::numeric_limits<unsigned>::max();
else uinc1 = (unsigned)a;
upom = uinc1%256;
i = (uinc1-upom)/256;
Expand Down
6 changes: 2 additions & 4 deletions tutorials/hist/hist103_THnSparse_hist.C
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@
#include "TStyle.h"
#include "TSystem.h"

#ifndef INT_MAX
#define INT_MAX std::numeric_limits<int>::max()
#endif
#include <limits>

class TTimeHists {
public:
Expand Down Expand Up @@ -217,7 +215,7 @@ void TTimeHists::SetupHist(EHist hist)
gSystem->GetMemInfo(&meminfo);
Int_t size = 1;
for (Int_t d = 0; d < fDim; ++d) {
if ((Int_t)(size * sizeof(Float_t)) > INT_MAX / (fBins + 2) ||
if ((Int_t)(size * sizeof(Float_t)) > std::numeric_limits<int>::max() / (fBins + 2) ||
(meminfo.fMemFree > 0 && meminfo.fMemFree / 2 < (Int_t)(size * sizeof(Float_t) / 1000 / 1000)))
throw std::bad_alloc();
size *= (fBins + 2);
Expand Down
Loading