Re: floating point problems
- From: "G Patel" <gaya.patel@xxxxxxxxx>
- Date: 2 Feb 2006 16:58:41 -0800
Christian Bau wrote:
In article <1138925921.972033.243230@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"G Patel" <gaya.patel@xxxxxxxxx> wrote:
Christian Bau wrote:
In article <1138919097.179821.174410@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"G Patel" <gaya.patel@xxxxxxxxx> wrote:
Now I still have a bug happening near the end of my program. When I do
the test for right triangle, I take the difference between (hyp^2) and
the sum of the other two sides squared. Sometimes this results in the
floating point value -0.00000 (i checked by printing it out). When I
compare the result with 0.0 it fails.
It looks like you are calculating a square root, and then you take the
result and square it immediately. That is a bit pointless, isn't it?
Just takes code and execution time and adds a bit of rounding error.
Better write a function that returns the square of the distance between
two points.
My hands are tied because I have to use the distance function's
distances inside my right triangle function.
If it is a homework problem, tell your instructor that his method is
stupid. If it is not a homework problem, your hands are not tied.
It is a school assignment and I have the program working except that
our programs are testing automatically by some program.
He lets us know 8 of the cases, the rest are hidden. 2 of the cases
seem impossible to implement in computers (and yes, we have to sqrt in
a distance function, and then resquare it in the actualy "figuring out"
function).
One of the cases has a triangle with a side that is of length sqrt(41),
which is irrational. So when the other function gets it and resquares
it, accuracy is lost. Yet his testing program wants an exactly
solution (no approximate one allowed for this case).
The other case has a triangle with 2 really large sides and one very
small sides. He wants us to get it within some tolerance, but i can't
seem to "keep" the information from the small side to "stick" within
the sqrt function.
I am going to email him and tell him that his cases are ridiculous (in
a nice way).
Thanks.
.
- Follow-Ups:
- Re: floating point problems
- From: Christian Bau
- Re: floating point problems
- From: Coos Haak
- Re: floating point problems
- References:
- floating point problems
- From: G Patel
- Re: floating point problems
- From: P.J. Plauger
- Re: floating point problems
- From: Rod Pemberton
- Re: floating point problems
- From: G Patel
- Re: floating point problems
- From: Christian Bau
- Re: floating point problems
- From: G Patel
- Re: floating point problems
- From: Christian Bau
- floating point problems
- Prev by Date: Re: Parallel port command
- Next by Date: Re: floating point problems
- Previous by thread: Re: floating point problems
- Next by thread: Re: floating point problems
- Index(es):
Relevant Pages
|
Loading