Replace MAX_FLOAT32 by standard FLT_MAX and remove unused MIN_FLOAT32

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2018-07-02 11:15:37 +02:00
parent 7ec337d9b8
commit f6c3c8cf4d
20 changed files with 52 additions and 47 deletions

View File

@ -22,6 +22,7 @@
#include "tprintf.h"
#include <algorithm>
#include <cfloat> // for FLT_MAX
namespace tesseract {
@ -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;
}

View File

@ -19,6 +19,7 @@
#include "normalis.h"
#include <cfloat> // for FLT_MAX
#include <cstdlib>
#include "allheaders.h"
@ -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;

View File

@ -21,6 +21,7 @@
#define RATNGS_H
#include <cassert>
#include <cfloat> // for FLT_MAX
#include "clst.h"
#include "elst.h"
@ -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;
@ -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

View File

@ -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

View File

@ -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...
@ -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;

View File

@ -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);
}

View File

@ -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.
@ -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];
@ -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

View File

@ -26,6 +26,7 @@
#include "emalloc.h"
#include <algorithm>
#include <cfloat> // for FLT_MAX
#include <cstdio>
#include <cmath>
@ -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) {
@ -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)

View File

@ -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 {

View File

@ -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) {

View File

@ -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;

View File

@ -18,6 +18,7 @@
#include "ctc.h"
#include <algorithm>
#include <cfloat> // for FLT_MAX
#include <memory>
#include "genericvector.h"
@ -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])));
@ -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);
@ -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;

View File

@ -17,6 +17,7 @@
///////////////////////////////////////////////////////////////////////
#include "networkio.h"
#include <cfloat> // for FLT_MAX
#include "allheaders.h"
#include "functions.h"
@ -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 {
@ -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) {
@ -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) {

View File

@ -28,6 +28,7 @@
#include "baselinedetect.h"
#include <algorithm>
#include <cfloat> // for FLT_MAX
#include <cmath>
#include "allheaders.h"
#include "blobbox.h"
@ -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;

View File

@ -18,6 +18,7 @@
**********************************************************************/
#include <math.h>
#include <cfloat> // for FLT_MAX
#include <vector> // for std::vector
#include "makerow.h"
#include "pitsync1.h"
@ -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;
@ -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;
@ -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
@ -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++)

View File

@ -17,7 +17,8 @@
*
**********************************************************************/
#include <math.h>
#include <cfloat> // for FLT_MAX
#include <cmath>
#include "pitsync1.h"
ELISTIZE (FPSEGPT) CLISTIZE (FPSEGPT_LIST)
@ -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;
@ -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
@ -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 ();

View File

@ -21,6 +21,7 @@
#include "config_auto.h"
#endif
#include <cfloat> // for FLT_MAX
#include "globaloc.h"
#include "blread.h"
#include "blobbox.h"
@ -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);

View File

@ -331,7 +331,7 @@ SEAM* Wordrec::improve_one_blob(const GenericVector<BLOB_CHOICE*>& blob_choices,
bool italic_blob,
WERD_RES* word,
int* blob_number) {
float rating_ceiling = MAX_FLOAT32;
float rating_ceiling = FLT_MAX;
SEAM *seam = nullptr;
do {
*blob_number = select_blob_to_split_from_fixpt(fixpt);
@ -541,14 +541,14 @@ int Wordrec::select_blob_to_split(
float rating_ceiling, bool split_next_to_fragment) {
BLOB_CHOICE *blob_choice;
int x;
float worst = -MAX_FLOAT32;
float worst = -FLT_MAX;
int worst_index = -1;
float worst_near_fragment = -MAX_FLOAT32;
float worst_near_fragment = -FLT_MAX;
int worst_index_near_fragment = -1;
const CHAR_FRAGMENT **fragments = nullptr;
if (chop_debug) {
if (rating_ceiling < MAX_FLOAT32)
if (rating_ceiling < FLT_MAX)
tprintf("rating_ceiling = %8.4f\n", rating_ceiling);
else
tprintf("rating_ceiling = No Limit\n");

View File

@ -63,7 +63,7 @@ void ViterbiStateEntry::Print(const char *msg) const {
void LanguageModelState::Clear() {
viterbi_state_entries.clear();
viterbi_state_entries_prunable_length = 0;
viterbi_state_entries_prunable_max_cost = MAX_FLOAT32;
viterbi_state_entries_prunable_max_cost = FLT_MAX;
viterbi_state_entries_length = 0;
}

View File

@ -193,7 +193,7 @@ ELISTIZEH(ViterbiStateEntry)
struct LanguageModelState {
LanguageModelState() :
viterbi_state_entries_prunable_length(0),
viterbi_state_entries_prunable_max_cost(MAX_FLOAT32),
viterbi_state_entries_prunable_max_cost(FLT_MAX),
viterbi_state_entries_length(0) {}
~LanguageModelState() {}