Hi, On 24.04.2016 15:50, andy pugh wrote: > On 24 April 2016 at 13:47, Philipp Burch <[email protected]> wrote: >> It's not actually strange, that's just the behaviour of floating point >> numbers. > > Well, yes and no. > > My entry in the Glade UI is an a textual form. The version that > appears in the .ui file is also in a textual form. > I think it is reasonable to expect the two to match. >
if you consider the implementation, then no. When you enter the value
(in text form), then it is converted to a floating point number and
stored that way. Why? Because that is how the Spinbox operates
internally. It does not care about text, it only cares about numbers.
When you save the UI file, this number happens to be converted into a
string again because it is a textual file format (XML), but this text
does have nothing to do with what you entered originally. If Glade would
support a binary output format, then there would most likely not be a
textual representation of this number at all.
> This behaviour appears to lead to a problem where zero is not exactly
> represented in the output from the spinbox, despite the value in the
> spinbox being displayed as zero.
> (and FP certainly can represent zero exactly)
>
This problem is not linked to the representation in text form, it is an
inherent problem of FP calculations:
>>> x=.15+.15+.15-.45
>>> x
-5.551115123125783e-17
The spinbox displays this as zero only because it is rounding. This is a
bit counterintuitive, it is usually a bad idea to round during
calculations. In this case, it might actually improve the result if we'd
rounded on the way. I'd still not recommend it, though. In my opinion,
rounding should be the task of whatever entity comes last in the
calculations and is responsible for displaying (NOT storing) the value.
In our case here, that would be the G-Code generator at the end. So,
instead of
>>> print('X' + str(x))
X-5.55111512313e-17
better use
>>> print('X%.6f' % (x,))
X-0.000000
The signed zero is not really useful, but this should not make the
interpreter cough.
Cheers,
Philipp
signature.asc
Description: OpenPGP digital signature
------------------------------------------------------------------------------ Find and fix application performance issues faster with Applications Manager Applications Manager provides deep performance insights into multiple tiers of your business applications. It resolves application problems quickly and reduces your MTTR. Get your free trial! https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________ Emc-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/emc-users
