Skip to content

Commit

Permalink
Avoid crafting_success_roll returning NaN
Browse files Browse the repository at this point in the history
The crafting_success_roll could end up computing 0.0/0.0.  This happened
to work, but more by luck than design, so check for that case
explicitly.

(NaN values are unsafe given that we're compiling with -ffast-math).
  • Loading branch information
jbytheway committed Jan 25, 2020
1 parent a1ee2fe commit df15d25
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,11 @@ double player::crafting_success_roll( const recipe &making ) const
const double skill_roll = dice( skill_dice, skill_sides );
const double diff_roll = dice( diff_dice, diff_sides );

if( diff_roll == 0 ) {
// Automatic success
return 2;
}

return skill_roll / diff_roll;
}

Expand Down

0 comments on commit df15d25

Please sign in to comment.