10 divided by 3 *multiplied with 3 is not 10 again??
-
Back in the day, I had to write a Pascal function called "AlmostEqual". I passed the values to be checked for "equality", and how many decimal places to check. I converted both values to strings with the appropriate formatting specs, and compared the strings. We needed different precisions depending on where we were in the math calculations. My suggestion is to NOT check doubles for equality without doing something along the same lines.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001John Simmons / outlaw programmer wrote:
I passed the values to be checked for "equality", and how many decimal places to check. I converted both values to strings with the appropriate formatting specs, and compared the strings.
Wow, now that's a hack. Wouldn't it be nicer to do something like this?
bool AlmostEqual(double a, double b, int decimalPlaces)
{
double diff = 0f;
for(int i=0; iOr would this be inaccurate again?
-
Jörgen Sigvardsson wrote:
The most accurate way to present that number, is to present it as 10/3, or 3 1/3 if you wish.
I learned that it can be written as 3.3. Was my teacher wrong? :suss:
Cheers, Vikram.
"whoever I am, I'm not other people" - Corinna John.
No he wasn't wrong, but it's not a real number either, and not very intuitive for further computations. What is 0.36 times 33? Took you a while eh? What is 4/11 times 33? :)
-- Hey, TiVo! Suggest this!
-
Back in the day, I had to write a Pascal function called "AlmostEqual". I passed the values to be checked for "equality", and how many decimal places to check. I converted both values to strings with the appropriate formatting specs, and compared the strings. We needed different precisions depending on where we were in the math calculations. My suggestion is to NOT check doubles for equality without doing something along the same lines.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001I often write functions like this:
bool FuzzyEqual(double l, double r, double fuzz) {
return abs(l - r) < fuzz;
}Then I adjust the "fuzz" in accordance to the needed precision.
-- Secreted by the Comedy Bee
-
Yesterday I questioned, if the possibility of 0 will mean impossible. I dont think so. If you have an infinite number of choices and take one, the possibility is 1 / infinite = 0 but not impossible. All of you said, that 1 / infinite is nearly 0, but not 0. That's astonishing me. So if 10 / 3 = Charly, and Charly * 3 = result, the result is nearly 10, but not 10???
0 is not a number so dividing any number by 0 returns "not a number" in mathematical terms(abbr. NaN). Elaine :rose:
-
John Simmons / outlaw programmer wrote:
I passed the values to be checked for "equality", and how many decimal places to check. I converted both values to strings with the appropriate formatting specs, and compared the strings.
Wow, now that's a hack. Wouldn't it be nicer to do something like this?
bool AlmostEqual(double a, double b, int decimalPlaces)
{
double diff = 0f;
for(int i=0; iOr would this be inaccurate again?
That's quite inefficient.. :~
-- Featuring GRATUITOUS ALIEN NUDITY
-
0 is not a number so dividing any number by 0 returns "not a number" in mathematical terms(abbr. NaN). Elaine :rose:
0 is not a number? I think you need to revisit and revise your post... ;)
-- For External Use Only
-
0 is not a number? I think you need to revisit and revise your post... ;)
-- For External Use Only
Technically, 0 is lack of a number. The romans didn't have 0 which limited them mathematically (it was actually invented in India and spread to Europe via Arab traders). Elaine :rose:
-
Technically, 0 is lack of a number. The romans didn't have 0 which limited them mathematically (it was actually invented in India and spread to Europe via Arab traders). Elaine :rose:
-
No he wasn't wrong, but it's not a real number either, and not very intuitive for further computations. What is 0.36 times 33? Took you a while eh? What is 4/11 times 33? :)
-- Hey, TiVo! Suggest this!
Actually, in mathematics 0.3 is a real number. To a computer with limited precision it cannot be accurately represented, but in general infinitely repeating decimals are definitely real. Even things like pi and e are real numbers even though all their digits cannot be computed. That's what makes the set of real numbers bigger then the set of rational numbers.
and of course [they] outsource their technical support to a land where English bears little resemblance to the language I speak - Christopher Duncan
-
Jörgen Sigvardsson wrote:
The most accurate way to present that number, is to present it as 10/3, or 3 1/3 if you wish.
I learned that it can be written as 3.3. Was my teacher wrong? :suss:
Cheers, Vikram.
"whoever I am, I'm not other people" - Corinna John.
Your teacher was right. All decimals are real even infinitely repeating ones.
and of course [they] outsource their technical support to a land where English bears little resemblance to the language I speak - Christopher Duncan