Skip to content

Commit

Permalink
Use namespaced math functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingranade committed Apr 14, 2020
1 parent 7848a17 commit 2bd671f
Show file tree
Hide file tree
Showing 70 changed files with 246 additions and 235 deletions.
4 changes: 2 additions & 2 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1037,8 +1037,8 @@ static void butchery_drops_harvest( item *corpse_item, const mtype &mt, player &
// apply skill before converting to items, but only if mass_ratio is defined
roll *= roll_drops();
monster_weight_remaining -= roll;
roll = ceil( static_cast<double>( roll ) /
to_gram( item::find_type( entry.drop )->weight ) );
roll = std::ceil( static_cast<double>( roll ) /
to_gram( item::find_type( entry.drop )->weight ) );
} else {
monster_weight_remaining -= roll * to_gram( ( item::find_type( entry.drop ) )->weight );
}
Expand Down
6 changes: 3 additions & 3 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ static activity_reason_info can_do_activity_there( const activity_id &act, playe
return activity_reason_info::fail( NO_ZONE );
}
// if the vehicle is moving or player is controlling it.
if( abs( veh->velocity ) > 100 || veh->player_in_control( g->u ) ) {
if( std::abs( veh->velocity ) > 100 || veh->player_in_control( g->u ) ) {
return activity_reason_info::fail( NO_ZONE );
}
for( const npc &guy : g->all_npcs() ) {
Expand Down Expand Up @@ -1323,8 +1323,8 @@ static activity_reason_info can_do_activity_there( const activity_id &act, playe
continue;
}
const int max_lift = p.best_nearby_lifting_assist( src_loc );
const int lvl = ceil( units::quantity<double, units::mass::unit_type>( base.weight() ) /
TOOL_LIFT_FACTOR );
const int lvl = std::ceil( units::quantity<double, units::mass::unit_type>( base.weight() ) /
TOOL_LIFT_FACTOR );
const bool use_aid = max_lift >= lvl;
const bool use_str = p.can_lift( base );
if( !( use_aid || use_str ) ) {
Expand Down
4 changes: 2 additions & 2 deletions src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1702,9 +1702,9 @@ std::string points_left::to_string()
_( "Points left: <color_%s>%d</color>%c<color_%s>%d</color>%c<color_%s>%d</color>=<color_%s>%d</color>" ),
stat_points_left() >= 0 ? "light_gray" : "red", stat_points,
trait_points >= 0 ? '+' : '-',
trait_points_left() >= 0 ? "light_gray" : "red", abs( trait_points ),
trait_points_left() >= 0 ? "light_gray" : "red", std::abs( trait_points ),
skill_points >= 0 ? '+' : '-',
skill_points_left() >= 0 ? "light_gray" : "red", abs( skill_points ),
skill_points_left() >= 0 ? "light_gray" : "red", std::abs( skill_points ),
is_valid() ? "light_gray" : "red", stat_points + trait_points + skill_points );
} else if( limit == ONE_POOL ) {
return string_format( _( "Points left: %4d" ), skill_points_left() );
Expand Down
4 changes: 2 additions & 2 deletions src/avatar_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ bool avatar_action::move( avatar &you, map &m, int dx, int dy, int dz )
veh_closed_door = dpart >= 0 && !veh1->parts[dpart].open;
}

if( veh0 != nullptr && abs( veh0->velocity ) > 100 ) {
if( veh0 != nullptr && std::abs( veh0->velocity ) > 100 ) {
if( veh1 == nullptr ) {
if( query_yn( _( "Dive from moving vehicle?" ) ) ) {
g->moving_vehicle_dismount( dest_loc );
Expand Down Expand Up @@ -619,7 +619,7 @@ void avatar_action::autoattack( avatar &you, map &m )
} );

const tripoint diff = best.pos() - you.pos();
if( abs( diff.x ) <= 1 && abs( diff.y ) <= 1 && diff.z == 0 ) {
if( std::abs( diff.x ) <= 1 && std::abs( diff.y ) <= 1 && diff.z == 0 ) {
move( you, m, tripoint( diff.xy(), 0 ) );
return;
}
Expand Down
22 changes: 12 additions & 10 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ bool Character::activate_bionic( int b, bool eff_only )
int vehwindspeed = 0;
if( optional_vpart_position vp = g->m.veh_at( pos() ) ) {
// vehicle velocity in mph
vehwindspeed = abs( vp->vehicle().velocity / 100 );
vehwindspeed = std::abs( vp->vehicle().velocity / 100 );
}
const oter_id &cur_om_ter = overmap_buffer.ter( global_omt_location() );
/* cache g->get_temperature( player location ) since it is used twice. No reason to recalc */
Expand Down Expand Up @@ -1095,7 +1095,7 @@ bool Character::burn_fuel( int b, bool start )
const optional_vpart_position vp = g->m.veh_at( pos() );
if( vp ) {
// vehicle velocity in mph
vehwindspeed = abs( vp->vehicle().velocity / 100 );
vehwindspeed = std::abs( vp->vehicle().velocity / 100 );
}
const double windpower = get_local_windpower( g->weather.windspeed + vehwindspeed,
overmap_buffer.ter( global_omt_location() ), pos(), g->weather.winddirection,
Expand Down Expand Up @@ -1175,7 +1175,7 @@ void Character::passive_power_gen( int b )
const optional_vpart_position vp = g->m.veh_at( pos() );
if( vp ) {
// vehicle velocity in mph
vehwindspeed = abs( vp->vehicle().velocity / 100 );
vehwindspeed = std::abs( vp->vehicle().velocity / 100 );
}
const double windpower = get_local_windpower( g->weather.windspeed + vehwindspeed,
overmap_buffer.ter( global_omt_location() ), pos(), g->weather.winddirection,
Expand Down Expand Up @@ -1553,13 +1553,14 @@ void Character::bionics_uninstall_failure( int difficulty, int success, float ad
{
// "success" should be passed in as a negative integer representing how far off we
// were for a successful removal. We use this to determine consequences for failing.
success = abs( success );
success = std::abs( success );

// failure level is decided by how far off the character was from a successful removal, and
// this is scaled up or down by the ratio of difficulty/skill. At high skill levels (or low
// difficulties), only minor consequences occur. At low skill levels, severe consequences
// are more likely.
const int failure_level = static_cast<int>( sqrt( success * 4.0 * difficulty / adjusted_skill ) );
const int failure_level = static_cast<int>( std::sqrt( success * 4.0 * difficulty /
adjusted_skill ) );
const int fail_type = std::min( 5, failure_level );

if( fail_type <= 0 ) {
Expand Down Expand Up @@ -1617,13 +1618,14 @@ void Character::bionics_uninstall_failure( monster &installer, player &patient,

// "success" should be passed in as a negative integer representing how far off we
// were for a successful removal. We use this to determine consequences for failing.
success = abs( success );
success = std::abs( success );

// failure level is decided by how far off the monster was from a successful removal, and
// this is scaled up or down by the ratio of difficulty/skill. At high skill levels (or low
// difficulties), only minor consequences occur. At low skill levels, severe consequences
// are more likely.
const int failure_level = static_cast<int>( sqrt( success * 4.0 * difficulty / adjusted_skill ) );
const int failure_level = static_cast<int>( std::sqrt( success * 4.0 * difficulty /
adjusted_skill ) );
const int fail_type = std::min( 5, failure_level );

bool u_see = sees( patient );
Expand Down Expand Up @@ -1780,7 +1782,7 @@ int bionic_manip_cos( float adjusted_skill, int bionic_difficulty )
// to reserve bionics for characters with the appropriate skill. For more difficult bionics, the
// curve flattens out just above 80%
chance_of_success = static_cast<int>( ( 100 * skill_difficulty_parameter ) /
( skill_difficulty_parameter + sqrt( 1 / skill_difficulty_parameter ) ) );
( skill_difficulty_parameter + std::sqrt( 1 / skill_difficulty_parameter ) ) );

return chance_of_success;
}
Expand Down Expand Up @@ -2258,13 +2260,13 @@ void Character::bionics_install_failure( const bionic_id &bid, const std::string
{
// "success" should be passed in as a negative integer representing how far off we
// were for a successful install. We use this to determine consequences for failing.
success = abs( success );
success = std::abs( success );

// failure level is decided by how far off the character was from a successful install, and
// this is scaled up or down by the ratio of difficulty/skill. At high skill levels (or low
// difficulties), only minor consequences occur. At low skill levels, severe consequences
// are more likely.
int failure_level = static_cast<int>( sqrt( success * 4.0 * difficulty / adjusted_skill ) );
int failure_level = static_cast<int>( std::sqrt( success * 4.0 * difficulty / adjusted_skill ) );
int fail_type = ( failure_level > 5 ? 5 : failure_level );
bool drop_cbm = false;
add_msg( m_neutral, _( "The installation is a failure." ) );
Expand Down
8 changes: 4 additions & 4 deletions src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1441,11 +1441,11 @@ void cata_tiles::get_window_tile_counts( const int width, const int height, int
int &rows ) const
{
if( tile_iso ) {
columns = ceil( static_cast<double>( width ) / tile_width ) * 2 + 4;
rows = ceil( static_cast<double>( height ) / ( tile_width / 2.0 - 1 ) ) * 2 + 4;
columns = std::ceil( static_cast<double>( width ) / tile_width ) * 2 + 4;
rows = std::ceil( static_cast<double>( height ) / ( tile_width / 2.0 - 1 ) ) * 2 + 4;
} else {
columns = ceil( static_cast<double>( width ) / tile_width );
rows = ceil( static_cast<double>( height ) / tile_height );
columns = std::ceil( static_cast<double>( width ) / tile_width );
rows = std::ceil( static_cast<double>( height ) / tile_height );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/cata_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ bool match_include_exclude( const std::string &text, std::string filter )

double logarithmic( double t )
{
return 1 / ( 1 + exp( -t ) );
return 1 / ( 1 + std::exp( -t ) );
}

double logarithmic_range( int min, int max, int pos )
Expand Down
30 changes: 16 additions & 14 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1687,7 +1687,7 @@ void Character::recalc_sight_limits()
static float threshold_for_range( float range )
{
constexpr float epsilon = 0.01f;
return LIGHT_AMBIENT_MINIMAL / exp( range * LIGHT_TRANSPARENCY_OPEN_AIR ) - epsilon;
return LIGHT_AMBIENT_MINIMAL / std::exp( range * LIGHT_TRANSPARENCY_OPEN_AIR ) - epsilon;
}

float Character::get_vision_threshold( float light_level ) const
Expand Down Expand Up @@ -2616,8 +2616,8 @@ units::mass Character::weight_carried_with_tweaks( const item_tweaks &tweaks ) c
}
// Exclude wielded item if using lifting tool
if( weaponweight + ret > weight_capacity() ) {
const float liftrequirement = ceil( units::to_gram<float>( weaponweight ) / units::to_gram<float>
( TOOL_LIFT_FACTOR ) );
const float liftrequirement = std::ceil( units::to_gram<float>( weaponweight ) /
units::to_gram<float>( TOOL_LIFT_FACTOR ) );
if( g->new_game || best_nearby_lifting_assist() < liftrequirement ) {
ret += weaponweight;
}
Expand Down Expand Up @@ -4454,7 +4454,7 @@ void Character::update_health( int external_modifiers )
// For small differences, it changes 4 points per day
// For large ones, up to ~40% of the difference per day
int health_change = effective_healthy_mod - get_healthy() + external_modifiers;
mod_healthy( sgn( health_change ) * std::max( 1, abs( health_change ) / 10 ) );
mod_healthy( sgn( health_change ) * std::max( 1, std::abs( health_change ) / 10 ) );

// And healthy_mod decays over time.
// Slowly near 0, but it's hard to overpower it near +/-100
Expand Down Expand Up @@ -5133,7 +5133,7 @@ void Character::update_bodytemp()
int vehwindspeed = 0;
const optional_vpart_position vp = g->m.veh_at( pos() );
if( vp ) {
vehwindspeed = abs( vp->vehicle().velocity / 100 ); // vehicle velocity in mph
vehwindspeed = std::abs( vp->vehicle().velocity / 100 ); // vehicle velocity in mph
}
const oter_id &cur_om_ter = overmap_buffer.ter( global_omt_location() );
bool sheltered = g->is_sheltered( pos() );
Expand Down Expand Up @@ -5247,8 +5247,8 @@ void Character::update_bodytemp()
frostbite_timer[bp] -= std::max( 5, h_radiation );
}
// 111F (44C) is a temperature in which proteins break down: https://en.wikipedia.org/wiki/Burn
blister_count += h_radiation - 111 > 0 ? std::max( static_cast<int>( sqrt( h_radiation - 111 ) ),
0 ) : 0;
blister_count += h_radiation - 111 > 0 ?
std::max( static_cast<int>( std::sqrt( h_radiation - 111 ) ), 0 ) : 0;

const bool pyromania = has_trait( trait_PYROMANIA );
// BLISTERS : Skin gets blisters from intense heat exposure.
Expand Down Expand Up @@ -5414,7 +5414,8 @@ void Character::update_bodytemp()
rounding_error = 1;
}
if( temp_cur[bp] != temp_conv[bp] ) {
temp_cur[bp] = static_cast<int>( temp_difference * exp( -0.002 ) + temp_conv[bp] + rounding_error );
temp_cur[bp] = static_cast<int>( temp_difference * std::exp( -0.002 ) + temp_conv[bp] +
rounding_error );
}
// This statement checks if we should be wearing our bonus warmth.
// If, after all the warmth calculations, we should be, then we have to recalculate the temperature.
Expand All @@ -5428,7 +5429,8 @@ void Character::update_bodytemp()
}
if( temp_before != temp_conv[bp] ) {
temp_difference = temp_before - temp_conv[bp];
temp_cur[bp] = static_cast<int>( temp_difference * exp( -0.002 ) + temp_conv[bp] + rounding_error );
temp_cur[bp] = static_cast<int>( temp_difference * std::exp( -0.002 ) + temp_conv[bp] +
rounding_error );
}
}
int temp_after = temp_cur[bp];
Expand Down Expand Up @@ -6968,9 +6970,9 @@ int Character::get_bmr() const
Values are for males, and average!
*/
const int equation_constant = 5;
return ceil( metabolic_rate_base() * activity_level * ( units::to_gram<int>
( bodyweight() / 100.0 ) +
( 6.25 * height() ) - ( 5 * age() ) + equation_constant ) );
return std::ceil( metabolic_rate_base() * activity_level * ( units::to_gram<int>
( bodyweight() / 100.0 ) +
( 6.25 * height() ) - ( 5 * age() ) + equation_constant ) );
}

void Character::increase_activity_level( float new_level )
Expand Down Expand Up @@ -8724,7 +8726,7 @@ void Character::apply_persistent_morale()
}
// The penalty starts at 1 at min_time and scales up to max_unhappiness at max_time.
const float t = ( total_time - min_time ) / ( max_time - min_time );
const int pen = ceil( lerp_clamped( 0, max_unhappiness, t ) );
const int pen = std::ceil( lerp_clamped( 0, max_unhappiness, t ) );
if( pen > 0 ) {
add_morale( MORALE_PERM_NOMAD, -pen, -pen, 1_minutes, 1_minutes, true );
}
Expand Down Expand Up @@ -9287,7 +9289,7 @@ std::list<item> Character::use_charges( const itype_id &what, int qty,
qty -= std::min( qty, bio );
}

int adv = charges_of( "adv_UPS_off", static_cast<int>( ceil( qty * 0.6 ) ) );
int adv = charges_of( "adv_UPS_off", static_cast<int>( std::ceil( qty * 0.6 ) ) );
if( adv > 0 ) {
std::list<item> found = use_charges( "adv_UPS_off", adv );
res.splice( res.end(), found );
Expand Down
2 changes: 1 addition & 1 deletion src/computer_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ void computer_session::action_amigara_log()
reset_terminal();
print_line( _( "SITE %d%d%d\n"
"PERTINENT FOREMAN LOGS WILL BE PREPENDED TO NOTES" ),
g->get_levx(), g->get_levy(), abs( g->get_levz() ) );
g->get_levx(), g->get_levy(), std::abs( g->get_levz() ) );
print_text( "%s", SNIPPET.random_from_category( "amigara4" ).value_or( translation() ) );
print_gibberish_line();
print_gibberish_line();
Expand Down
4 changes: 2 additions & 2 deletions src/consumption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ std::pair<int, int> Character::fun_for( const item &comest ) const
}

if( has_active_bionic( bio_taste_blocker ) &&
get_power_level() > units::from_kilojoule( abs( comest.get_comestible_fun() ) ) &&
get_power_level() > units::from_kilojoule( std::abs( comest.get_comestible_fun() ) ) &&
fun < 0 ) {
fun = 0;
}
Expand Down Expand Up @@ -1033,7 +1033,7 @@ void Character::modify_stimulation( const islot_comestible &comest )
{
const int current_stim = get_stim();
if( comest.stim != 0 &&
( abs( current_stim ) < ( abs( comest.stim ) * 3 ) ||
( std::abs( current_stim ) < ( std::abs( comest.stim ) * 3 ) ||
sgn( current_stim ) != sgn( comest.stim ) ) ) {
if( comest.stim < 0 ) {
set_stim( std::max( comest.stim * 3, current_stim + comest.stim ) );
Expand Down
2 changes: 1 addition & 1 deletion src/craft_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ std::vector<comp_selection<item_comp>> craft_command::check_item_components_miss
for( const auto &item_sel : item_selections ) {
itype_id type = item_sel.comp.type;
const item_comp component = item_sel.comp;
const int count = component.count > 0 ? component.count * batch_size : abs( component.count );
const int count = component.count > 0 ? component.count * batch_size : std::abs( component.count );

if( item::count_by_charges( type ) && count > 0 ) {
switch( item_sel.use_from ) {
Expand Down
4 changes: 2 additions & 2 deletions src/crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,7 @@ comp_selection<item_comp> player::select_item_component( const std::vector<item_

for( const auto &component : components ) {
itype_id type = component.type;
int count = ( component.count > 0 ) ? component.count * batch : abs( component.count );
int count = ( component.count > 0 ) ? component.count * batch : std::abs( component.count );

if( item::count_by_charges( type ) && count > 0 ) {
int map_charges = map_inv.charges_of( type, INT_MAX, filter );
Expand Down Expand Up @@ -1603,7 +1603,7 @@ std::list<item> player::consume_items( map &m, const comp_selection<item_comp> &
const tripoint &loc = origin;
const bool by_charges = item::count_by_charges( selected_comp.type ) && selected_comp.count > 0;
// Count given to use_amount/use_charges, changed by those functions!
int real_count = ( selected_comp.count > 0 ) ? selected_comp.count * batch : abs(
int real_count = ( selected_comp.count > 0 ) ? selected_comp.count * batch : std::abs(
selected_comp.count );
// First try to get everything from the map, than (remaining amount) from player
if( is.use_from & use_from_map ) {
Expand Down
6 changes: 3 additions & 3 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ bool Creature::sees( const Creature &critter ) const
( critter.has_flag( MF_NIGHT_INVISIBILITY ) && g->m.light_at( critter.pos() ) <= LL_LOW ) ||
( critter.is_underwater() && !is_underwater() && g->m.is_divable( critter.pos() ) ) ||
( g->m.has_flag_ter_or_furn( TFLAG_HIDE_PLACE, critter.pos() ) &&
!( abs( posx() - critter.posx() ) <= 1 && abs( posy() - critter.posy() ) <= 1 &&
abs( posz() - critter.posz() ) <= 1 ) ) ) {
!( std::abs( posx() - critter.posx() ) <= 1 && std::abs( posy() - critter.posy() ) <= 1 &&
std::abs( posz() - critter.posz() ) <= 1 ) ) ) {
return false;
}
if( ch != nullptr ) {
Expand Down Expand Up @@ -421,7 +421,7 @@ Creature *Creature::auto_find_hostile_target( int range, int &boo_hoo, int area
bool maybe_boo = false;
if( angle_iff ) {
int tangle = coord_to_angle( pos(), m->pos() );
int diff = abs( u_angle - tangle );
int diff = std::abs( u_angle - tangle );
// Player is in the angle and not too far behind the target
if( ( diff + iff_hangle > 360 || diff < iff_hangle ) &&
( dist * 3 / 2 + 6 > pldist ) ) {
Expand Down
Loading

0 comments on commit 2bd671f

Please sign in to comment.