02-01-2006 05:22 PM
CC hit the real nail on the head. Why would you want to use Q&R with floating point numbers, it was meant to be used with integers only? Think about it. Just the word "Remainder" means it is an integer function. I must confess that I never really used Q&R with floats before this thread. So this whole arguement is now pointless. Lets have a good laugh.
One thing for sure, I learned a lot about binary representation of floats thanx to JPD's in depth explanations. Merci, mon cousin!!!
02-01-2006 07:11 PM
LabVIEW, C'est LabVIEW
02-02-2006 04:06 AM
02-02-2006 08:00 AM
Don't want to restart the whole discussion... Just some final thoughts...
I think that one should make a distinction between the bits that a variable is composed of, and the real number that the variable is supposed to represent. The question is how do you want people to work with their routines. Do we want the user to be bothered by the fact that the computer cannot accurately represent the number 0.2 internally?
I don't like the idea that we should let quantization errors influence the result of the calculation. Normally, quantization and rounding errors are automatically taken care of at the input and output. In both input and output rounding occurs. (Default 6 digits in Labview) With most calculations, rounding as the final output is sufficient to make sure that you aren't bothered by the inaccurate representation of the real numbers by the computer.
However, in routines like QR, the inaccurate number representation does influence the result. Suddenly the least-significant bit, has become the most-significant bit.... For a faithfull representation of the numbers, the QR routine should use the same accuracy as the input and output. The rest of the digits are only there to make it possible for the computer to calculate numbers that it can't accurately represent, without affecting the end result.
I don't agree with the idea that an alternative QR would be less accurate. Quantization and rounding errors have allready made the input inaccurate before it reaches the QR routine. Hence, also the output of ANY calculation on those numbers will be inaccurate to at least the same degree. Obviously, a QR routine that rounds after 10 digits, is inaccurate in the following digits. However, a QR routine that doesn't round at all, can be inaccurate in the first digit! Because it takes inherently inaccurate last digits as significant.
Concluding:
Purely seen as some operation on some bits, the QR routine is accurate.
But seen as an operation on a real number (which is represented in a finite accuracy), the current QR routine is inaccurate.
And then NI only has to make sure that it's clear to the user which implementation is being used, and what the effects are. That should be simple enough. For example, having an 'equal?' vi with a square icon, in stead of the triangular shape is probably allready a clear enough distinction. (The rest can be in the description and help)
02-02-2006 08:56 AM
Anthony, others:
In the past where I've seen discussions about new feature requests or changed behavior requests, the NI folks tend to ask for some example "use cases." So, what are some specific examples where Q-R behavior needs to be different? What was the app that brought it to your attention in the first place?
What I've gathered from your posts is that you're predominantly concerned with situations where one or both of the inputs x & y come directly from user-entered values on a front panel. And the problem you see is that the value that the user intends to enter is not exactly equal to the internal representation of the value. I.e., a user enters "0.2" but the IEEE representation isn't exactly 0.2 (The same thing may occur for programmer-entered constant values on the block diagram, but arguably the programmer can be expected to anticipate floating point issues more than the user.)
The issue keeps coming down to: users think in base 10, floating point values are stored in base 2. The two will only occasionally agree exactly.
I'm beginning to think that the only real solution without drawbacks (to LV programmers -- I'm sure there's plenty of drawbacks to NI) is a new numeric datatype. Maybe something similar to a DBL, with bits laid out to represent integer values of mantissa and exponent. The only difference is that it would use a base-10 exponent. Support this datatype for simple numeric primitives (add,mult,log10,Q-R,...). Let the datatype be subservient so it when paired with a base-2 DBL as inputs to a numeric primitive, the base-10 datatype gets coerced -- this minimizes breakage of existing code.
I don't know the field and am too lazy/pressed for time to search now. But I would guess there are some math library implementations out there that have already done this sort of thing? Maybe some sort of de facto standard?
Anyway, this type of solution allows a programmer to use the new base-10 datatype for user-entered values, and to maintain base-10 through a series of (simple) calculations that will produce user-expected results. It would require NI to develop a math library, but would not require additional icons to the numeric palette. Existing functions would just be overloaded for the new datatype.
Ok, any comments? What drawbacks am I missing?
-Kevin P.
02-02-2006 09:02 AM
Doing it that way would result in a Quotient of 5.000000000000000000 and a Remainder of -0.0000000000000000555111512312578270.
@Kevin Price wrote:I haven't carefully thought through or experimented with the Q-R function in particular. But as far as being able to program around the inaccuracies, wouldn't it be enough to simply compare the remainder to the dividend? If it's "approximately equal" (based on methods more-or-less acknowledged necessary for floating point in this thread), subtract the dividend from the remainder and adjust the quotient.Somewhat of a pain, granted, but rougly on par with the pain of handling floating-point equality, no?
02-02-2006 09:12 AM
I must admit that after all this discussion I went through a bunch of my old code to see where I had used the Q&R function and (thankfully) I only found one place where I had used it with floats. In that one case I was separating the integer and fractional components of real numbers and the divisor (Y) value into the Q&R function was a 1.0 which should be safe from any rounding errors in any number base currently in use (at least on this planet):smileyvery-happy:
@tbob wrote:
Why would you want to use Q&R with floating point numbers, it was meant to be used with integers only? Think about it. Just the word "Remainder" means it is an integer function.
02-02-2006 09:14 AM - edited 02-02-2006 09:14 AM
LabVIEW does not do any rounding on the actual number at all anywhere! It is only the display routine in a numeric control that has by default a precision of 6 digits (and actually does some smart rounding too) but the number that flows through the wire always stays the same with the maximum precision (~16 digits for a double) for that datatype.
@Anthony de Vries wrote:
I don't like the idea that we should let quantization errors influence the result of the calculation. Normally, quantization and rounding errors are automatically taken care of at the input and output. In both input and output rounding occurs. (Default 6 digits in Labview) With most calculations, rounding as the final output is sufficient to make sure that you aren't bothered by the inaccurate representation of the real numbers by the computer.
Message Edited by rolfk on 02-02-2006 04:25 PM
02-02-2006 09:25 AM
02-02-2006 09:30 AM
To me a negative remainder is actually more unintuitive than the normal behaviour.