Re: floating point problems




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.

.



Relevant Pages

  • intelligence
    ... then a triangle, therefore is missing the square. ... D the half squares are turned around 90° against the clockwise direction, ... square and circle and indicate at the same ...
    (misc.news.internet.discuss)
  • Re: floating point problems
    ... It looks like you are calculating a square root, ... Better write a function that returns the square of the distance between ... distances inside my right triangle function. ... therefore the sum on the left ...
    (comp.lang.c)
  • Re: "Euclids Fourteenth Book
    ... square on the hypotenuse. ... right triangle itself. ... Given that areas of plane figures scale as the square of any ... If you add curvature the Pythagorean theorem holds ...
    (talk.origins)
  • Re: 3 quilt patterns
    ... A technique cannot be copyrighted, but the specific instructions, written ... three of the sides to inscribe a triangle in this, ... making what I called a "triangle in a square." ... As for the pattern being ...
    (rec.crafts.textiles.quilting)
  • Re: color interpolation discrepancies
    ... > specifically, I expected them to look like the last square, which at ... For a textured quad you are correct, ... all by the "other" corner in the other triangle. ... be red, all the way across, as the blue corner is not considered. ...
    (comp.graphics.api.opengl)

Loading