Sum lack of precision!

While working ahead instead of twiddling my thumbs, doing other work I'm supposed to be doing, and waiting for my latest submission to be nitpicked, I had a go at assignment 7. I get the expected answer up to 2 iterations of the loop, then all hell breaks loose! At least precision-wise. What's up with that? Where should I look for enlightenment oh wise ones?

Had a go at Sum to see what you were talking about. Yikes! Talk about not being in Kansas anymore. I suppose it has something to do with how rounding works with floating-point numbers, or ultimately with the IEEE Standard for floating-point arithmetic. I'm looking at the Java Language Specification as well as at some descriptions of the IEEE Standard, but as I'm no math geek, I could easily get lost in there. I await with you for pearls of wisdom from the anointed.

This is not specific to Java. Try a basic Computer Science book (I don't have one to recommend) for an explanation of the way computers store and use floating point numbers.

JavaBeginnersFaq"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt

Adam Vinueza
Ranch Hand

Joined: Apr 16, 2001
Posts: 76

posted May 27, 2001 09:54:00

0

Thanks Marilyn! I feel sheepish saying this, but I don't have any basic computer science textbooks: I'm coming to programming from philosophy, where they don't teach floating-point arithmetic. It's this sort of thing that continually reminds me of all the bizarre gaps in my knowledge. I'll ferret around for some basic text.

For anybody (like me) who's made or is making the transition to a computer-related profession from a liberal arts background, I'd highly recommend the book CODE: The Hidden Language of Computer Hardware and Software by Charles Petzold. It's hard to explain what this book is about -- it ties together all sorts of seemingly disparate topics related to how computers work, with a focus on computing as a communicative activity. It's great fun to read. Kind of gives a sense of the things I (hopefully) would have learned about in a traditional computer science program. You won't find extensive discussions of data structures or algorithms, like you would in an introductory computer science text, but there are a few pages on floating-point numbers. [This message has been edited by Michael Matola (edited May 28, 2001).]

Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1199

posted May 27, 2001 22:16:00

0

So is there any way to fix it, or is this one of those piles of elephant poop in the middle of the room that everybody notices but just doesn't talk about?

Johannes de Jong
tumbleweed
Bartender

Joined: Jan 27, 2001
Posts: 5089

posted May 28, 2001 00:13:00

0

I love your elephant poop analogy Must say I always do talk about the elephant poop when I see it, but I'm normally in the Kruger Park when I do talk about it I bet there is a very good explanation why it goes wrong and I bet there are even some very clever people that actually understand why, I'm not one of them. The only thing that I do know is, I try and avoid float as far as I can.

Adam, don't worry...you aren't the only one here coming from Philosophy Carol, there is a class we used in Grains ( don't want to give anything away... ) that I think has a Sister class to handle Decimals correctly. At least I hope so since my company applications rely heavily on ACCURATE decimals! ------------------ I'm a soldier in the NetScape Wars... Joel

Wait a minute, I'm trying to think of something clever to say...<p>Joel

Don't sell a philosophy background short! I got my undergraduate degree in philosophy as well, and I can tell you that all those symbolic logic classes provided an excellent background for programming!

Carol, Technically there isn't a way to "fix" floating point numbers, but there are algorithms and methods that have been developed to minimize error when using floating point numbers. I took a class a long time ago called Numerical Methods (CS414). I can say my career has not hinged on the information dispersed in this incredibly boring class. The textbook is still in publication if you want to delve into it. Elementary Numerical Analysis: An Algorithmic Approach You can pick up a used copy for just $16 at amazon! Michael

Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1199

posted May 29, 2001 19:24:00

0

Thanks for the info- I'm wondering if we're supposed to make this work or just humbly accept the results we get and consider ourselves warned?

Michael Pearson
Ranch Hand

Joined: Mar 11, 2001
Posts: 351

posted May 29, 2001 19:56:00

0

Carol, Do a search of the Cattle Drive and I think you'll find old comments referring to the intent of the Sum exercise.Post from 4/6/2001 I'm at the same stage of the Cattle Drive that you are at, but my impression from previous posts is that we are suppose to do the exercise and than explain the results in our e-mail when submitting Java-7. Good Luck, Michael [ edited to update link -ds ] [ November 02, 2002: Message edited by: Dirk Schreckmann ]

Johannes de Jong
tumbleweed
Bartender

Joined: Jan 27, 2001
Posts: 5089

posted May 29, 2001 23:20:00

0

Originally posted by Carol Murphy:Thanks for the info- I'm wondering if we're supposed to make this work or just humbly accept the results we get and consider ourselves warned?

[This message has been edited by Pauline McNamara (edited June 11, 2001).]

Paul Ralph
Ranch Hand

Joined: Aug 10, 2000
Posts: 312

posted Jun 11, 2001 11:51:00

0

Ouch. Light reading, it ain't. I tried skimming it and promptly made my headache worse. I sure hope Marilyn doesn't want that technical of an answer for Sum. BTW, I was a Mathematics/Actuarial Science major. Serious flashbacks. Paul R

Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012

6

posted Jun 11, 2001 13:31:00

0

Yikes! Printed that one out and I'm sure it won't take long for those pages to hit the recycling pile (unread). Followed the link you gave Richard - now that's more like it.

[This message has been edited by Pauline McNamara (edited June 12, 2001).]