Fix debug crash due to probability being outside 0-1 (#12616)

This commit is contained in:
Kevin Zheng
2022-11-16 06:22:28 -08:00
committed by GitHub
parent 4b2c3b9221
commit 10019cdabd

View File

@@ -112,8 +112,10 @@ public class MutationSystem : EntitySystem
return; return;
} }
// Starting number of bits that are high, between 0 and n. // Starting number of bits that are high, between 0 and bits.
int n = (int)Math.Round((val - min) / (max - min) * bits); int n = (int)Math.Round((val - min) / (max - min) * bits);
// val may be outside the range of min/max due to starting prototype values, so clamp
n = Math.Clamp(n, 0, bits);
// Probability that the bit flip increases n. // Probability that the bit flip increases n.
float p_increase = 1-(float)n/bits; float p_increase = 1-(float)n/bits;