c# - (How) does debugging change the workflow of the program? -
consider following simple program:
var dblmax = double.maxvalue; var result = (dblmax * 1000) / 1800; console.writeline(result);
when build in debug mode , run (ctrl+f5) or debug (f5) it, prints 9.987140856842e+307
.
when switch release mode , run (ctrl+f5) it, prints 8
infinity.
i understand difference due compiler optimization done in release mode.
however, if debug (f5) same build in release mode, prints 9.987140856842e+307
again!
how fact debugging change result of calculation?
edit:
i not ask why debug mode , release mode yield different results. wonder why release mode yielding different results depending on whether debug (f5) or not (ctrl+f5).
when debugging jitter behaves different.
for 1 thing, local variables in many cases have lifetimes changed in order inspectable. consider hitting breakpoint after variable used during calculation. if jitter knows variable not going used after expression, , didn't prolong lifetime of variable, end not being able @ variable, core feature of debugging.
the jiter has clear knowledge when variable useful still have lying around. if during time register available might end using register store variable in.
however, debugger attached might decide instead use memory location because lifetime changed enough register isn't available part of code.
floating point registers of cpu have higher precision corresponding floating point storage formats, means once either lift value out of register , memory, or store in memory whole time, experience lower precision.
the difference between release , debug build can end dictating these things, can presence of debugger.
additionally, there can differences between different .net runtime versions can affect this.
writing floating point code correctly requires intimate knowledge attempting , how various parts of machine , platform interfere. try avoid writing code this.
Comments
Post a Comment