Skip to content

Commit

Permalink
clang -Wimplicit-int-float-conversion fixes (#38886)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingranade authored Mar 19, 2020
1 parent abe7f1b commit f7bfc38
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/lightmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1239,8 +1239,12 @@ float fastexp( float x )
float f;
int i;
} u, v;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpragmas"
#pragma GCC diagnostic ignored "-Wimplicit-int-float-conversion"
u.i = static_cast<long long>( 6051102 * x + 1056478197 );
v.i = static_cast<long long>( 1056478197 - 6051102 * x );
#pragma GCC diagnostic pop
return u.f / v.f;
}

Expand Down
11 changes: 6 additions & 5 deletions src/monmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <memory>
#include <ostream>
#include <list>
#include <cfloat>

#include "avatar.h"
#include "bionics.h"
Expand Down Expand Up @@ -246,16 +247,16 @@ float monster::rate_target( Creature &c, float best, bool smart ) const
{
const auto d = rl_dist_fast( pos(), c.pos() );
if( d <= 0 ) {
return INT_MAX;
return FLT_MAX;
}

// Check a very common and cheap case first
if( !smart && d >= best ) {
return INT_MAX;
return FLT_MAX;
}

if( !sees( c ) ) {
return INT_MAX;
return FLT_MAX;
}

if( !smart ) {
Expand All @@ -273,7 +274,7 @@ float monster::rate_target( Creature &c, float best, bool smart ) const
return int( d ) / power;
}

return INT_MAX;
return FLT_MAX;
}

void monster::plan()
Expand Down Expand Up @@ -467,7 +468,7 @@ void monster::plan()
wandf = 2;
target = nullptr;
// Swarm to the furthest ally you can see
} else if( rating < INT_MAX && rating > dist && wandf <= 0 ) {
} else if( rating < FLT_MAX && rating > dist && wandf <= 0 ) {
target = &mon;
dist = rating;
}
Expand Down
3 changes: 2 additions & 1 deletion src/npcmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <tuple>
#include <cmath>
#include <type_traits>
#include <cfloat>

#include "activity_handlers.h"
#include "avatar.h"
Expand Down Expand Up @@ -215,7 +216,7 @@ tripoint npc::good_escape_direction( bool include_pos )
return rating;
};

float best_rating = include_pos ? rate_pt( pos(), 0.0f ) : INT_MAX;
float best_rating = include_pos ? rate_pt( pos(), 0.0f ) : FLT_MAX;
candidates.emplace_back( pos() );

std::map<direction, float> adj_map;
Expand Down
5 changes: 3 additions & 2 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <climits>
#include <type_traits>
#include <cfloat>

#include "cata_utility.h"
#include "catacharset.h"
Expand Down Expand Up @@ -218,8 +219,8 @@ void options_manager::add_external( const std::string &sNameIn, const std::strin
thisOpt.iSet = 0;
break;
case cOpt::CVT_FLOAT:
thisOpt.fMin = INT_MIN;
thisOpt.fMax = INT_MAX;
thisOpt.fMin = FLT_MIN;
thisOpt.fMax = FLT_MAX;
thisOpt.fDefault = 0;
thisOpt.fSet = 0;
thisOpt.fStep = 1;
Expand Down

0 comments on commit f7bfc38

Please sign in to comment.