-funsafe-math-optimizations is a default flag¶
Since 10 November 2026 every C/C++ unit builds with -funsafe-math-optimizations
(tools/config/toolchain.json flags). -ffast-math produces the same code for every function
in the tree, so the two cannot be told apart; the narrower flag is the one recorded.
Evidence¶
ZSoundObject::SetVolumeAttenuationis an inline atzsndobj.hlines 776 to 780 of the original. Its line table has code on all five lines, the layout ofif (x > 1.0f) x = 1.0f; else if (x < 0.0f) x = 0.0f;, and themin.s/max.sinstructions sit on the two assignment lines. GCC 3.2 turns anifintomin.s/max.sonly in if-conversion, and only with this flag. The inline ismin.s/max.sin units of audiolib, engine/audio, engine/eventsbase, engine/fysix, engine/geomsbase, engine/zwindows and four hitman3 directories, so the flag is not per library.SetVolumeAttenuation(0.0f, 0)in the BindToRoom updater leavesmin.sof the constants 0.0 and 1.0 in the code. The<?operator folds that at compile time.- 593
min.s/max.sinstructions exist in game C++ functions and 462 of them belong to the unit's own source lines. IOI's shared code also built with MSVC, which has no<?. - A float division by a constant that is not a power of two survives as
div.sin fewer than 30 functions of the whole game, and the ones examined divide by the result of an inline (fPitch / DegToRad(50.0f)), which the flag does not convert. - Whole-tree sweep: 21 matched functions changed, 1 draft became exact, 12 drafts improved and 13 got worse. All 21 were sources shaped around the missing flag, and each now reads more naturally or agrees with the line table.
How the 21 were rewritten¶
| Function | Old source | New source |
|---|---|---|
ZPostFilter::SetDepthBlurriness, SetHeatShimmerSpeed |
if (!(f >= c)) f = 0.0f; m = f; |
m = f >= c ? f : 0.0f; |
CParticle1D::VerletG |
F * dt * (invMass * dt) |
F * invMass * (dt * dt) |
ZCheckVisible::SetFOV, SetVerticalFOV |
<? clamp and angle * 0.5f * 0.01745329f |
fast_cos(DegToRad(fclamp(fFov, 0.0f, 360.0f) * 0.5f)) |
ZGEOM::GetPointBoundDistance |
two ternary maxima | nested if (x > y) { if (x > z) return x; } else { if (y > z) return y; } return z; |
ZBoatMoveModel::GlobalBoneUpdate |
if (v && !(dt < c)) { ... } |
if (!v \|\| dt < c) return; |
ZHM3CoverFinder::CreateBoxCover |
b = false; if (!(h < 50.0f)) b = true; |
if (h < 50.0f) b = false; else b = true; |
ZHM3LevelControlM05::BurnWife, ZHitman3::UpdateBloodTrails |
if (!(a < b)) return; |
body nested in if (a < b) { ... } |
ZHitman3ControlMouseStrafe::UpdateTurn |
one product of four factors | product of three, then *= MOUSE_TURN_SCALE |
ZHM3Control::CalcPosScale, ZWINOBJ::CalcPosScale |
vp * fScaleY * (fPers * res) |
vp * res * fPers * fScaleY |
ZDrawBuffer::ViewAspectXY |
one expression | three statements, as lines 28 to 30 of the original |
ZHFlow::RootVectorToMapDirection |
a * c1 * 65536.0f |
a *= c1; then a * 65536.0f (lines 2660, 2661) |
ZHM3Camera1stPerson::UpdateCameraPosition |
fPitch / 0.8726645f |
fPitch / DegToRad(50.0f) |
ZHitman3::PlayHitmanSound |
vol * 5.12f * 100.0f |
two statements (zsndobj.h lines 375, 376) |
ZHM3InventoryMenu::CalcCurrentPosition |
expressions inline | fRadiusX, fRadiusZ locals (lines 435, 436) |
Zhm3Actor__Dialoglisten, Dialogtalk |
r < 0.5f ? 0 : 1 as the argument |
if (r < 0.5f) lType = 0; else lType = 1; |
Zhm3Actor__Playactorspeech |
if (!(d < 3000.0f)) return; |
if (bGraph && d < 3000.0f) { } else { return; } (the block at lines 2261 to 2271 compiled to nothing) |
Rules¶
- Clamps and min/max: plain
if,else ifora < b ? a : b. Do not add<?/>?. - Constant divisor: write the division.
x / 255.0fandx * (1.0f / 255.0f)are the same code; 60 lines with reciprocal forms were turned back into divisions. - Two multiplications by constants in a row in the original: two statements, or one of the
constants belongs to an inline (
DegToRad, a setter). c.lt.s a, bfollowed bybc1f: the source testsa < bpositively and the other arm is theelse. A negation or>=compiles toc.le.s b, awithbc1t.cond ? 0 : 1on floats is folded to the inverted comparison. Where the original keepsc.lt.sand loads 0 then 1, the source is anif/elseor negates an inline's result.
The shared ZMIN and ZMAX templates in engine/system/minmaxoperator.h use ordinary conditional expressions.