From Saturday, Nov 23rd 7:00 PM CST - Sunday, Nov 24th 7:45 AM CST, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Saturday, Nov 23rd 7:00 PM CST - Sunday, Nov 24th 7:45 AM CST, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
08-16-2009 02:39 PM
Ravens Fan wrote:Try your code with a negative number and see if it makes sense.
Great catch! Knew I had to hurry with you guys involved...
Now it works. OP wants to deal with FP representations and Banker's rounding, so I'll let you guys handle it.
08-16-2009 02:46 PM
TonP said:Here's a solution that should work for: Any number, Any base (decimal is base 10), Any precision .
Sorry, this has gotten way out of hand for my application and
way too complicated for my application. I've got my answer
that fits my data range.
08-16-2009 02:50 PM
PointOnePa wrote:TonP said:Here's a solution that should work for: Any number, Any base (decimal is base 10), Any precision .
Sorry, this has gotten way out of hand for my application and
way too complicated for my application. I've got my answer
that fits my data range.
Yes, I understand that, but is your solution flexible?
However here is a negative proof solution:
It is the first time I ever used the Sign functionality.
Ton
08-16-2009 02:51 PM - edited 08-16-2009 02:52 PM
Here's yet another alternative for 3 digits (-99.9..99.9). If you don't need negative, simply delete the irrelevant parts. 🙂
This code assumes that the input is in the correct range, else you would need to also coerce the absolute integer to 0..999.
08-16-2009 03:00 PM
altenbach said: Here's yet another alternative for 3 digits
Yeah, this is what I ended up doing as described in a previous post, except without the for-loop,
which is a much cleaner implementation that what I posted in Float_to_Int3.gif . Thanks.
08-16-2009 03:05 PM - edited 08-16-2009 03:08 PM
@TonP wrote:
However here is a negative proof solution:
Ton
Kudos for (s)he who finds the bug. (without re-coding it).
Ton
08-16-2009 03:21 PM
TonP wrote:Kudos for (s)he who finds the bug. (without re-coding it).
The fact it suffers from the floating point issues, I don't consider a bug. Is it a feature that all of the digits will be negative if the number is < 0?
08-16-2009 04:11 PM
It should not suffer from floating point issues, could you describe this a little bit more?
Is it a feature that all of the digits will be negative if the number is < 0?
Yes, consider '-13', that means -1 times 10 and -3 times 1.
It is also valid to negate the units.
Ton
08-16-2009 04:54 PM - edited 08-16-2009 05:03 PM
Sorry if I am mistaken, but since I didn't code it you'll have to tell me. I assume if you put in for example 1.4, you'll get 1.399 or something similar. Not a bug, just a fact of life in floating point math.
All digits being negative is certainly fine, just not sure if it was the effect you were shooting for.
08-17-2009 02:11 PM
Zero sets all units to infinity.
Ton