Skip to content

Commit f6c3c8c

Browse files
committed
Replace MAX_FLOAT32 by standard FLT_MAX and remove unused MIN_FLOAT32
Signed-off-by: Stefan Weil <[email protected]>
1 parent 7ec337d commit f6c3c8c

20 files changed

+52
-47
lines changed

src/ccstruct/detlinefit.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "tprintf.h"
2323

2424
#include <algorithm>
25+
#include <cfloat> // for FLT_MAX
2526

2627
namespace tesseract {
2728

@@ -190,8 +191,7 @@ double DetLineFit::ConstrainedFit(double m, float* c) {
190191
double cos = 1.0 / sqrt(1.0 + m * m);
191192
FCOORD direction(cos, m * cos);
192193
ICOORD line_pt;
193-
double error = ConstrainedFit(direction, -MAX_FLOAT32, MAX_FLOAT32, false,
194-
&line_pt);
194+
double error = ConstrainedFit(direction, -FLT_MAX, FLT_MAX, false, &line_pt);
195195
*c = line_pt.y() - line_pt.x() * m;
196196
return error;
197197
}

src/ccstruct/normalis.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "normalis.h"
2121

22+
#include <cfloat> // for FLT_MAX
2223
#include <cstdlib>
2324

2425
#include "allheaders.h"
@@ -431,7 +432,7 @@ void DENORM::XHeightRange(int unichar_id, const UNICHARSET& unicharset,
431432
// Default return -- accept anything.
432433
*yshift = 0.0f;
433434
*min_xht = 0.0f;
434-
*max_xht = MAX_FLOAT32;
435+
*max_xht = FLT_MAX;
435436

436437
if (!unicharset.top_bottom_useful())
437438
return;

src/ccstruct/ratngs.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define RATNGS_H
2222

2323
#include <cassert>
24+
#include <cfloat> // for FLT_MAX
2425

2526
#include "clst.h"
2627
#include "elst.h"
@@ -418,9 +419,9 @@ class WERD_CHOICE : public ELIST_LINK {
418419
length_ = 0;
419420
adjust_factor_ = 1.0f;
420421
rating_ = 0.0;
421-
certainty_ = MAX_FLOAT32;
422+
certainty_ = FLT_MAX;
422423
min_x_height_ = 0.0f;
423-
max_x_height_ = MAX_FLOAT32;
424+
max_x_height_ = FLT_MAX;
424425
permuter_ = NO_PERM;
425426
unichars_in_script_order_ = false; // Tesseract is strict left-to-right.
426427
dangerous_ambig_found_ = false;
@@ -439,7 +440,7 @@ class WERD_CHOICE : public ELIST_LINK {
439440
inline void make_bad() {
440441
length_ = 0;
441442
rating_ = kBadRating;
442-
certainty_ = -MAX_FLOAT32;
443+
certainty_ = -FLT_MAX;
443444
}
444445

445446
/// This function assumes that there is enough space reserved

src/ccutil/host.h

-5
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ using BOOL8 = unsigned char;
4848

4949
#endif /* _WIN32 */
5050

51-
#define MAX_FLOAT32 std::numeric_limits<float>::max()
52-
53-
// Minimum positive value ie 1e-37ish.
54-
#define MIN_FLOAT32 std::numeric_limits<float>::min()
55-
5651
// Defines
5752
#ifndef TRUE
5853
#define TRUE 1

src/classify/adaptmatch.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#include "fontinfo.h" // for ScoredFont, FontSet
4444
#include "genericvector.h" // for GenericVector
4545
#include "helpers.h" // for IntCastRounded, ClipToRange
46-
#include "host.h" // for FLOAT32, FALSE, MAX_FLOAT32, TRUE
46+
#include "host.h" // for FLOAT32, FALSE, TRUE
4747
#include "intfx.h" // for BlobToTrainingSample, INT_FX_RESULT_S...
4848
#include "intmatcher.h" // for CP_RESULT_STRUCT, IntegerMatcher
4949
#include "intproto.h" // for INT_FEATURE_STRUCT, (anonymous), Clas...
@@ -1474,7 +1474,7 @@ void Classify::ConvertMatchesToChoices(const DENORM& denorm, const TBOX& box,
14741474
max_matches = MAX_MATCHES;
14751475
}
14761476

1477-
float best_certainty = -MAX_FLOAT32;
1477+
float best_certainty = -FLT_MAX;
14781478
for (int i = 0; i < Results->match.size(); i++) {
14791479
const UnicharRating& result = Results->match[i];
14801480
bool adapted = result.adapted;

src/classify/classify.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ void Classify::AddLargeSpeckleTo(int blob_length, BLOB_CHOICE_LIST *choices) {
221221
(rating_scale * blob_length);
222222
}
223223
BLOB_CHOICE* blob_choice = new BLOB_CHOICE(UNICHAR_SPACE, rating, certainty,
224-
-1, 0.0f, MAX_FLOAT32, 0,
224+
-1, 0.0f, FLT_MAX, 0,
225225
BCC_SPECKLE_CLASSIFIER);
226226
bc_it.add_to_end(blob_choice);
227227
}

src/classify/cluster.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "matrix.h"
2525
#include "tprintf.h"
2626
#include "danerror.h"
27+
#include <cfloat> // for FLT_MAX
2728
#include <cmath>
2829

2930
#define HOTELLING 1 // If true use Hotelling's test to decide where to split.
@@ -797,7 +798,7 @@ void MakePotentialClusters(ClusteringContext *context,
797798
CLUSTER *
798799
FindNearestNeighbor(KDTREE * Tree, CLUSTER * Cluster, FLOAT32 * Distance)
799800
#define MAXNEIGHBORS 2
800-
#define MAXDISTANCE MAX_FLOAT32
801+
#define MAXDISTANCE FLT_MAX
801802
{
802803
CLUSTER *Neighbor[MAXNEIGHBORS];
803804
FLOAT32 Dist[MAXNEIGHBORS];
@@ -2364,8 +2365,8 @@ void *FunctionParams, double InitialGuess, double Accuracy)
23642365

23652366
x = InitialGuess;
23662367
Delta = INITIALDELTA;
2367-
LastPosX = MAX_FLOAT32;
2368-
LastNegX = -MAX_FLOAT32;
2368+
LastPosX = FLT_MAX;
2369+
LastNegX = -FLT_MAX;
23692370
f = (*Function) ((CHISTRUCT *) FunctionParams, x);
23702371
while (Abs (LastPosX - LastNegX) > Accuracy) {
23712372
// keep track of outer bounds of current estimate

src/classify/kdtree.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "emalloc.h"
2727

2828
#include <algorithm>
29+
#include <cfloat> // for FLT_MAX
2930
#include <cstdio>
3031
#include <cmath>
3132

@@ -35,8 +36,8 @@
3536
/*-----------------------------------------------------------------------------
3637
Global Data Definitions and Declarations
3738
-----------------------------------------------------------------------------*/
38-
#define MINSEARCH -MAX_FLOAT32
39-
#define MAXSEARCH MAX_FLOAT32
39+
#define MINSEARCH -FLT_MAX
40+
#define MAXSEARCH FLT_MAX
4041

4142
// Helper function to find the next essential dimension in a cycle.
4243
static int NextLevel(KDTREE *tree, int level) {
@@ -497,7 +498,7 @@ bool KDTreeSearch::BoxIntersectsSearch(FLOAT32 *lower, FLOAT32 *upper) {
497498

498499
/* if this dimension is circular - check wraparound distance */
499500
if (dim->Circular) {
500-
FLOAT32 wrap_distance = MAX_FLOAT32;
501+
FLOAT32 wrap_distance = FLT_MAX;
501502
if (*query < *lower)
502503
wrap_distance = *query + dim->Max - dim->Min - *upper;
503504
else if (*query > *upper)

src/classify/mfoutline.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,11 @@ void ComputeDirection(MFEDGEPT *Start,
406406
Delta.y = Finish->Point.y - Start->Point.y;
407407
if (Delta.x == 0)
408408
if (Delta.y < 0) {
409-
Start->Slope = -MAX_FLOAT32;
409+
Start->Slope = -FLT_MAX;
410410
Start->Direction = south;
411411
}
412412
else {
413-
Start->Slope = MAX_FLOAT32;
413+
Start->Slope = FLT_MAX;
414414
Start->Direction = north;
415415
}
416416
else {

src/classify/normmatch.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ FLOAT32 Classify::ComputeNormMatch(CLASS_ID ClassId,
110110
return (1.0 - NormEvidenceOf (Match));
111111
}
112112

113-
BestMatch = MAX_FLOAT32;
113+
BestMatch = FLT_MAX;
114114
Protos = NormProtos->Protos[ClassId];
115115

116116
if (DebugMatch) {

src/dict/stopper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ int Dict::LengthOfShortestAlphaRun(const WERD_CHOICE &WordChoice) const {
463463

464464
int Dict::UniformCertainties(const WERD_CHOICE& word) {
465465
float Certainty;
466-
float WorstCertainty = MAX_FLOAT32;
466+
float WorstCertainty = FLT_MAX;
467467
float CertaintyThreshold;
468468
double TotalCertainty;
469469
double TotalCertaintySquared;

src/lstm/ctc.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "ctc.h"
1919

2020
#include <algorithm>
21+
#include <cfloat> // for FLT_MAX
2122
#include <memory>
2223

2324
#include "genericvector.h"
@@ -269,7 +270,7 @@ static double LogSumExp(double ln_x, double ln_y) {
269270

270271
// Runs the forward CTC pass, filling in log_probs.
271272
void CTC::Forward(GENERIC_2D_ARRAY<double>* log_probs) const {
272-
log_probs->Resize(num_timesteps_, num_labels_, -MAX_FLOAT32);
273+
log_probs->Resize(num_timesteps_, num_labels_, -FLT_MAX);
273274
log_probs->put(0, 0, log(outputs_(0, labels_[0])));
274275
if (labels_[0] == null_char_)
275276
log_probs->put(0, 1, log(outputs_(0, labels_[1])));
@@ -297,7 +298,7 @@ void CTC::Forward(GENERIC_2D_ARRAY<double>* log_probs) const {
297298

298299
// Runs the backward CTC pass, filling in log_probs.
299300
void CTC::Backward(GENERIC_2D_ARRAY<double>* log_probs) const {
300-
log_probs->Resize(num_timesteps_, num_labels_, -MAX_FLOAT32);
301+
log_probs->Resize(num_timesteps_, num_labels_, -FLT_MAX);
301302
log_probs->put(num_timesteps_ - 1, num_labels_ - 1, 0.0);
302303
if (labels_[num_labels_ - 1] == null_char_)
303304
log_probs->put(num_timesteps_ - 1, num_labels_ - 2, 0.0);
@@ -332,7 +333,7 @@ void CTC::NormalizeSequence(GENERIC_2D_ARRAY<double>* probs) const {
332333
for (int t = 0; t < num_timesteps_; ++t) {
333334
// Separate impossible path from unlikely probs.
334335
double prob = probs->get(t, u);
335-
if (prob > -MAX_FLOAT32)
336+
if (prob > -FLT_MAX)
336337
prob = ClippedExp(prob - max_logprob);
337338
else
338339
prob = 0.0;

src/lstm/networkio.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
///////////////////////////////////////////////////////////////////////
1818

1919
#include "networkio.h"
20+
#include <cfloat> // for FLT_MAX
2021

2122
#include "allheaders.h"
2223
#include "functions.h"
@@ -465,7 +466,7 @@ void NetworkIO::ScoresOverRange(int t_start, int t_end, int choice, int null_ch,
465466
float score = ProbToCertainty(line[choice]);
466467
float zero = ProbToCertainty(line[null_ch]);
467468
if (t == t_start) {
468-
ratings[2] = MAX_FLOAT32;
469+
ratings[2] = FLT_MAX;
469470
ratings[1] = -score;
470471
certs[1] = score;
471472
} else {
@@ -495,7 +496,7 @@ int NetworkIO::BestLabel(int t, int not_this, int not_that,
495496
float* score) const {
496497
ASSERT_HOST(!int_mode_);
497498
int best_index = -1;
498-
float best_score = -MAX_FLOAT32;
499+
float best_score = -FLT_MAX;
499500
const float* line = f_[t];
500501
for (int i = 0; i < f_.dim2(); ++i) {
501502
if (line[i] > best_score && i != not_this && i != not_that) {
@@ -719,7 +720,7 @@ float NetworkIO::MinOfMaxes() const {
719720
int width = Width();
720721
int num_features = NumFeatures();
721722
for (int t = 0; t < width; ++t) {
722-
float max_value = -MAX_FLOAT32;
723+
float max_value = -FLT_MAX;
723724
if (int_mode_) {
724725
const int8_t* column = i_[t];
725726
for (int i = 0; i < num_features; ++i) {

src/textord/baselinedetect.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "baselinedetect.h"
2929

3030
#include <algorithm>
31+
#include <cfloat> // for FLT_MAX
3132
#include <cmath>
3233
#include "allheaders.h"
3334
#include "blobbox.h"
@@ -289,8 +290,8 @@ void BaselineRow::SetupBlobDisplacements(const FCOORD& direction) {
289290
GenericVector<double> perp_blob_dists;
290291
displacement_modes_.truncate(0);
291292
// Gather the skew-corrected position of every blob.
292-
double min_dist = MAX_FLOAT32;
293-
double max_dist = -MAX_FLOAT32;
293+
double min_dist = FLT_MAX;
294+
double max_dist = -FLT_MAX;
294295
BLOBNBOX_IT blob_it(blobs_);
295296
#ifdef kDebugYCoord
296297
bool debug = false;

src/textord/pithsync.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
**********************************************************************/
1919

2020
#include <math.h>
21+
#include <cfloat> // for FLT_MAX
2122
#include <vector> // for std::vector
2223
#include "makerow.h"
2324
#include "pitsync1.h"
@@ -134,7 +135,7 @@ void FPCUTPT::assign( //constructor
134135
fwd_balance |= lead_flag;
135136

136137
xpos = x;
137-
cost = MAX_FLOAT32;
138+
cost = FLT_MAX;
138139
pred = nullptr;
139140
faked = faking;
140141
terminal = false;
@@ -241,7 +242,7 @@ void FPCUTPT::assign_cheap( //constructor
241242
fwd_balance |= lead_flag;
242243

243244
xpos = x;
244-
cost = MAX_FLOAT32;
245+
cost = FLT_MAX;
245246
pred = nullptr;
246247
faked = faking;
247248
terminal = false;
@@ -370,7 +371,7 @@ double check_pitch_sync2( //find segmentation
370371
zero_count, pitch, x, offset);
371372

372373
this_it = *blob_it;
373-
best_cost = MAX_FLOAT32;
374+
best_cost = FLT_MAX;
374375
best_end = nullptr;
375376
this_box = box_next (&this_it);//first box
376377
next_box = box_next (&this_it);//second box
@@ -551,7 +552,7 @@ double check_pitch_sync3( //find segmentation
551552
cutpts[x - array_origin].setup(&cutpts[0], array_origin, projection,
552553
zero_count, pitch, x, offset);
553554

554-
best_cost = MAX_FLOAT32;
555+
best_cost = FLT_MAX;
555556
best_end = nullptr;
556557
for (offset = -pitch_error, minindex = 0; offset < pitch_error;
557558
offset++, minindex++)

src/textord/pitsync1.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
*
1818
**********************************************************************/
1919

20-
#include <math.h>
20+
#include <cfloat> // for FLT_MAX
21+
#include <cmath>
2122
#include "pitsync1.h"
2223

2324
ELISTIZE (FPSEGPT) CLISTIZE (FPSEGPT_LIST)
@@ -99,7 +100,7 @@ FPSEGPT_LIST * prev_list //previous segment
99100
double factor; //cost function
100101
FPSEGPT_IT pred_it = prev_list;//for previuos segment
101102

102-
cost = MAX_FLOAT32;
103+
cost = FLT_MAX;
103104
pred = nullptr;
104105
faked = faking;
105106
terminal = FALSE;
@@ -218,7 +219,7 @@ double check_pitch_sync( //find segmentation
218219
lattice_it.add_before_then_move (segpts);
219220
min_index = 0;
220221
region_index = 1;
221-
best_cost = MAX_FLOAT32;
222+
best_cost = FLT_MAX;
222223
best_end = nullptr;
223224
min_it = *blob_it;
224225
min_box = box_next (&min_it); //first box
@@ -379,7 +380,7 @@ void make_illegal_segment( //find segmentation
379380
//previous points
380381
FPSEGPT_IT prevpt_it = prev_list;
381382

382-
best_cost = MAX_FLOAT32;
383+
best_cost = FLT_MAX;
383384
for (prevpt_it.mark_cycle_pt (); !prevpt_it.cycled_list ();
384385
prevpt_it.forward ()) {
385386
prevpt = prevpt_it.data ();

src/textord/tordmain.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "config_auto.h"
2222
#endif
2323

24+
#include <cfloat> // for FLT_MAX
2425
#include "globaloc.h"
2526
#include "blread.h"
2627
#include "blobbox.h"
@@ -739,7 +740,7 @@ void Textord::TransferDiacriticsToBlockGroups(BLOBNBOX_LIST* diacritic_blobs,
739740
// Linear search of the groups to find a matching rotation.
740741
float block_angle = block->re_rotation().angle();
741742
int best_g = 0;
742-
float best_angle_diff = MAX_FLOAT32;
743+
float best_angle_diff = FLT_MAX;
743744
for (int g = 0; g < groups.size(); ++g) {
744745
double angle_diff = fabs(block_angle - groups[g]->angle);
745746
if (angle_diff > M_PI) angle_diff = fabs(angle_diff - 2.0 * M_PI);

0 commit comments

Comments
 (0)