Skip to content

Commit

Permalink
Replace MAX_FLOAT32 by standard FLT_MAX and remove unused MIN_FLOAT32
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed Jul 2, 2018
1 parent 7ec337d commit f6c3c8c
Show file tree
Hide file tree
Showing 20 changed files with 52 additions and 47 deletions.
4 changes: 2 additions & 2 deletions src/ccstruct/detlinefit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "tprintf.h"

#include <algorithm>
#include <cfloat> // for FLT_MAX

namespace tesseract {

Expand Down Expand Up @@ -190,8 +191,7 @@ double DetLineFit::ConstrainedFit(double m, float* c) {
double cos = 1.0 / sqrt(1.0 + m * m);
FCOORD direction(cos, m * cos);
ICOORD line_pt;
double error = ConstrainedFit(direction, -MAX_FLOAT32, MAX_FLOAT32, false,
&line_pt);
double error = ConstrainedFit(direction, -FLT_MAX, FLT_MAX, false, &line_pt);
*c = line_pt.y() - line_pt.x() * m;
return error;
}
Expand Down
3 changes: 2 additions & 1 deletion src/ccstruct/normalis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "normalis.h"

#include <cfloat> // for FLT_MAX
#include <cstdlib>

#include "allheaders.h"
Expand Down Expand Up @@ -431,7 +432,7 @@ void DENORM::XHeightRange(int unichar_id, const UNICHARSET& unicharset,
// Default return -- accept anything.
*yshift = 0.0f;
*min_xht = 0.0f;
*max_xht = MAX_FLOAT32;
*max_xht = FLT_MAX;

if (!unicharset.top_bottom_useful())
return;
Expand Down
7 changes: 4 additions & 3 deletions src/ccstruct/ratngs.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define RATNGS_H

#include <cassert>
#include <cfloat> // for FLT_MAX

#include "clst.h"
#include "elst.h"
Expand Down Expand Up @@ -418,9 +419,9 @@ class WERD_CHOICE : public ELIST_LINK {
length_ = 0;
adjust_factor_ = 1.0f;
rating_ = 0.0;
certainty_ = MAX_FLOAT32;
certainty_ = FLT_MAX;
min_x_height_ = 0.0f;
max_x_height_ = MAX_FLOAT32;
max_x_height_ = FLT_MAX;
permuter_ = NO_PERM;
unichars_in_script_order_ = false; // Tesseract is strict left-to-right.
dangerous_ambig_found_ = false;
Expand All @@ -439,7 +440,7 @@ class WERD_CHOICE : public ELIST_LINK {
inline void make_bad() {
length_ = 0;
rating_ = kBadRating;
certainty_ = -MAX_FLOAT32;
certainty_ = -FLT_MAX;
}

/// This function assumes that there is enough space reserved
Expand Down
5 changes: 0 additions & 5 deletions src/ccutil/host.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ using BOOL8 = unsigned char;

#endif /* _WIN32 */

#define MAX_FLOAT32 std::numeric_limits<float>::max()

// Minimum positive value ie 1e-37ish.
#define MIN_FLOAT32 std::numeric_limits<float>::min()

// Defines
#ifndef TRUE
#define TRUE 1
Expand Down
4 changes: 2 additions & 2 deletions src/classify/adaptmatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include "fontinfo.h" // for ScoredFont, FontSet
#include "genericvector.h" // for GenericVector
#include "helpers.h" // for IntCastRounded, ClipToRange
#include "host.h" // for FLOAT32, FALSE, MAX_FLOAT32, TRUE
#include "host.h" // for FLOAT32, FALSE, TRUE
#include "intfx.h" // for BlobToTrainingSample, INT_FX_RESULT_S...
#include "intmatcher.h" // for CP_RESULT_STRUCT, IntegerMatcher
#include "intproto.h" // for INT_FEATURE_STRUCT, (anonymous), Clas...
Expand Down Expand Up @@ -1474,7 +1474,7 @@ void Classify::ConvertMatchesToChoices(const DENORM& denorm, const TBOX& box,
max_matches = MAX_MATCHES;
}

float best_certainty = -MAX_FLOAT32;
float best_certainty = -FLT_MAX;
for (int i = 0; i < Results->match.size(); i++) {
const UnicharRating& result = Results->match[i];
bool adapted = result.adapted;
Expand Down
2 changes: 1 addition & 1 deletion src/classify/classify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ void Classify::AddLargeSpeckleTo(int blob_length, BLOB_CHOICE_LIST *choices) {
(rating_scale * blob_length);
}
BLOB_CHOICE* blob_choice = new BLOB_CHOICE(UNICHAR_SPACE, rating, certainty,
-1, 0.0f, MAX_FLOAT32, 0,
-1, 0.0f, FLT_MAX, 0,
BCC_SPECKLE_CLASSIFIER);
bc_it.add_to_end(blob_choice);
}
Expand Down
7 changes: 4 additions & 3 deletions src/classify/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "matrix.h"
#include "tprintf.h"
#include "danerror.h"
#include <cfloat> // for FLT_MAX
#include <cmath>

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

x = InitialGuess;
Delta = INITIALDELTA;
LastPosX = MAX_FLOAT32;
LastNegX = -MAX_FLOAT32;
LastPosX = FLT_MAX;
LastNegX = -FLT_MAX;
f = (*Function) ((CHISTRUCT *) FunctionParams, x);
while (Abs (LastPosX - LastNegX) > Accuracy) {
// keep track of outer bounds of current estimate
Expand Down
7 changes: 4 additions & 3 deletions src/classify/kdtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "emalloc.h"

#include <algorithm>
#include <cfloat> // for FLT_MAX
#include <cstdio>
#include <cmath>

Expand All @@ -35,8 +36,8 @@
/*-----------------------------------------------------------------------------
Global Data Definitions and Declarations
-----------------------------------------------------------------------------*/
#define MINSEARCH -MAX_FLOAT32
#define MAXSEARCH MAX_FLOAT32
#define MINSEARCH -FLT_MAX
#define MAXSEARCH FLT_MAX

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

/* if this dimension is circular - check wraparound distance */
if (dim->Circular) {
FLOAT32 wrap_distance = MAX_FLOAT32;
FLOAT32 wrap_distance = FLT_MAX;
if (*query < *lower)
wrap_distance = *query + dim->Max - dim->Min - *upper;
else if (*query > *upper)
Expand Down
4 changes: 2 additions & 2 deletions src/classify/mfoutline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,11 @@ void ComputeDirection(MFEDGEPT *Start,
Delta.y = Finish->Point.y - Start->Point.y;
if (Delta.x == 0)
if (Delta.y < 0) {
Start->Slope = -MAX_FLOAT32;
Start->Slope = -FLT_MAX;
Start->Direction = south;
}
else {
Start->Slope = MAX_FLOAT32;
Start->Slope = FLT_MAX;
Start->Direction = north;
}
else {
Expand Down
2 changes: 1 addition & 1 deletion src/classify/normmatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ FLOAT32 Classify::ComputeNormMatch(CLASS_ID ClassId,
return (1.0 - NormEvidenceOf (Match));
}

BestMatch = MAX_FLOAT32;
BestMatch = FLT_MAX;
Protos = NormProtos->Protos[ClassId];

if (DebugMatch) {
Expand Down
2 changes: 1 addition & 1 deletion src/dict/stopper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ int Dict::LengthOfShortestAlphaRun(const WERD_CHOICE &WordChoice) const {

int Dict::UniformCertainties(const WERD_CHOICE& word) {
float Certainty;
float WorstCertainty = MAX_FLOAT32;
float WorstCertainty = FLT_MAX;
float CertaintyThreshold;
double TotalCertainty;
double TotalCertaintySquared;
Expand Down
7 changes: 4 additions & 3 deletions src/lstm/ctc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "ctc.h"

#include <algorithm>
#include <cfloat> // for FLT_MAX
#include <memory>

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

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

// Runs the backward CTC pass, filling in log_probs.
void CTC::Backward(GENERIC_2D_ARRAY<double>* log_probs) const {
log_probs->Resize(num_timesteps_, num_labels_, -MAX_FLOAT32);
log_probs->Resize(num_timesteps_, num_labels_, -FLT_MAX);
log_probs->put(num_timesteps_ - 1, num_labels_ - 1, 0.0);
if (labels_[num_labels_ - 1] == null_char_)
log_probs->put(num_timesteps_ - 1, num_labels_ - 2, 0.0);
Expand Down Expand Up @@ -332,7 +333,7 @@ void CTC::NormalizeSequence(GENERIC_2D_ARRAY<double>* probs) const {
for (int t = 0; t < num_timesteps_; ++t) {
// Separate impossible path from unlikely probs.
double prob = probs->get(t, u);
if (prob > -MAX_FLOAT32)
if (prob > -FLT_MAX)
prob = ClippedExp(prob - max_logprob);
else
prob = 0.0;
Expand Down
7 changes: 4 additions & 3 deletions src/lstm/networkio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
///////////////////////////////////////////////////////////////////////

#include "networkio.h"
#include <cfloat> // for FLT_MAX

#include "allheaders.h"
#include "functions.h"
Expand Down Expand Up @@ -465,7 +466,7 @@ void NetworkIO::ScoresOverRange(int t_start, int t_end, int choice, int null_ch,
float score = ProbToCertainty(line[choice]);
float zero = ProbToCertainty(line[null_ch]);
if (t == t_start) {
ratings[2] = MAX_FLOAT32;
ratings[2] = FLT_MAX;
ratings[1] = -score;
certs[1] = score;
} else {
Expand Down Expand Up @@ -495,7 +496,7 @@ int NetworkIO::BestLabel(int t, int not_this, int not_that,
float* score) const {
ASSERT_HOST(!int_mode_);
int best_index = -1;
float best_score = -MAX_FLOAT32;
float best_score = -FLT_MAX;
const float* line = f_[t];
for (int i = 0; i < f_.dim2(); ++i) {
if (line[i] > best_score && i != not_this && i != not_that) {
Expand Down Expand Up @@ -719,7 +720,7 @@ float NetworkIO::MinOfMaxes() const {
int width = Width();
int num_features = NumFeatures();
for (int t = 0; t < width; ++t) {
float max_value = -MAX_FLOAT32;
float max_value = -FLT_MAX;
if (int_mode_) {
const int8_t* column = i_[t];
for (int i = 0; i < num_features; ++i) {
Expand Down
5 changes: 3 additions & 2 deletions src/textord/baselinedetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "baselinedetect.h"

#include <algorithm>
#include <cfloat> // for FLT_MAX
#include <cmath>
#include "allheaders.h"
#include "blobbox.h"
Expand Down Expand Up @@ -289,8 +290,8 @@ void BaselineRow::SetupBlobDisplacements(const FCOORD& direction) {
GenericVector<double> perp_blob_dists;
displacement_modes_.truncate(0);
// Gather the skew-corrected position of every blob.
double min_dist = MAX_FLOAT32;
double max_dist = -MAX_FLOAT32;
double min_dist = FLT_MAX;
double max_dist = -FLT_MAX;
BLOBNBOX_IT blob_it(blobs_);
#ifdef kDebugYCoord
bool debug = false;
Expand Down
9 changes: 5 additions & 4 deletions src/textord/pithsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
**********************************************************************/

#include <math.h>
#include <cfloat> // for FLT_MAX
#include <vector> // for std::vector
#include "makerow.h"
#include "pitsync1.h"
Expand Down Expand Up @@ -134,7 +135,7 @@ void FPCUTPT::assign( //constructor
fwd_balance |= lead_flag;

xpos = x;
cost = MAX_FLOAT32;
cost = FLT_MAX;
pred = nullptr;
faked = faking;
terminal = false;
Expand Down Expand Up @@ -241,7 +242,7 @@ void FPCUTPT::assign_cheap( //constructor
fwd_balance |= lead_flag;

xpos = x;
cost = MAX_FLOAT32;
cost = FLT_MAX;
pred = nullptr;
faked = faking;
terminal = false;
Expand Down Expand Up @@ -370,7 +371,7 @@ double check_pitch_sync2( //find segmentation
zero_count, pitch, x, offset);

this_it = *blob_it;
best_cost = MAX_FLOAT32;
best_cost = FLT_MAX;
best_end = nullptr;
this_box = box_next (&this_it);//first box
next_box = box_next (&this_it);//second box
Expand Down Expand Up @@ -551,7 +552,7 @@ double check_pitch_sync3( //find segmentation
cutpts[x - array_origin].setup(&cutpts[0], array_origin, projection,
zero_count, pitch, x, offset);

best_cost = MAX_FLOAT32;
best_cost = FLT_MAX;
best_end = nullptr;
for (offset = -pitch_error, minindex = 0; offset < pitch_error;
offset++, minindex++)
Expand Down
9 changes: 5 additions & 4 deletions src/textord/pitsync1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
*
**********************************************************************/

#include <math.h>
#include <cfloat> // for FLT_MAX
#include <cmath>
#include "pitsync1.h"

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

cost = MAX_FLOAT32;
cost = FLT_MAX;
pred = nullptr;
faked = faking;
terminal = FALSE;
Expand Down Expand Up @@ -218,7 +219,7 @@ double check_pitch_sync( //find segmentation
lattice_it.add_before_then_move (segpts);
min_index = 0;
region_index = 1;
best_cost = MAX_FLOAT32;
best_cost = FLT_MAX;
best_end = nullptr;
min_it = *blob_it;
min_box = box_next (&min_it); //first box
Expand Down Expand Up @@ -379,7 +380,7 @@ void make_illegal_segment( //find segmentation
//previous points
FPSEGPT_IT prevpt_it = prev_list;

best_cost = MAX_FLOAT32;
best_cost = FLT_MAX;
for (prevpt_it.mark_cycle_pt (); !prevpt_it.cycled_list ();
prevpt_it.forward ()) {
prevpt = prevpt_it.data ();
Expand Down
3 changes: 2 additions & 1 deletion src/textord/tordmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "config_auto.h"
#endif

#include <cfloat> // for FLT_MAX
#include "globaloc.h"
#include "blread.h"
#include "blobbox.h"
Expand Down Expand Up @@ -739,7 +740,7 @@ void Textord::TransferDiacriticsToBlockGroups(BLOBNBOX_LIST* diacritic_blobs,
// Linear search of the groups to find a matching rotation.
float block_angle = block->re_rotation().angle();
int best_g = 0;
float best_angle_diff = MAX_FLOAT32;
float best_angle_diff = FLT_MAX;
for (int g = 0; g < groups.size(); ++g) {
double angle_diff = fabs(block_angle - groups[g]->angle);
if (angle_diff > M_PI) angle_diff = fabs(angle_diff - 2.0 * M_PI);
Expand Down
Loading

0 comments on commit f6c3c8c

Please sign in to comment.