Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang -Wimplicit-int-float-conversion fixes #38886

Merged
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
4 changes: 4 additions & 0 deletions src/lightmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1237,8 +1237,12 @@ float fastexp( float x )
float f;
int i;
} u, v;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpragmas"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it the same thing as I did in #38431?

#pragma GCC diagnostic ignored "-Wunknown-pragmas"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this one means "STFU about any warnings related to pragmas".
GCC was choking on the other ignored pragma because it didn't recognize the warning flag.

#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 @@ -194,7 +195,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