Here's the relevant code: areaPgram a b c = (fst b * snd c) - (snd b * fst c) + (fst a * snd b) - (snd a * fst b) + (snd a * fst c) - (fst a * snd c) norm ((x1, y1), (x2, y2)) = sqrt ((x1 - x2)^2 + (y1 - y2)^2) angle a b c = asin (areaPgram a b c / (norm (b, a) * norm (b, c))) ... Main> angle (1,0) (0,1) (1,2) nan.0 The problem appears to be in the "norm". Other test cases I could think of to try worked fine... I'm mystified. How can I work around this??? -Adrian
Are you reporting a bug in Hugs or asking us to debug your code? If you're reporting a bug in Hugs, it's helpful to pinpoint the error and explain why it is an error. For example, if you said 'print (asin 3.14)' produces 97 but should produce <whatever the right answer is>, we'd know what to run to reproduce the bug and we'd know what the bug is. Or, if you said "print (foo 3.14)" produces 9 and "print (bar 9)" produces 42 but "print (bar (foo 3.14))" produces 43, we'd know what your problem was. -- Alastair Reid reid@cs.utah.edu http://www.cs.utah.edu/~reid/
Alastair Reid (reid@cs.utah.edu) wrote:
Are you reporting a bug in Hugs or asking us to debug your code?
Sorry, I should have been more clear. I think it's a bug. Main> :version -- Hugs Version February 2001 Main> asin (-2 / 2.0) -1.5708 Main> norm (b, a) * norm (b, c) 2.0 Main> asin (-2 / (norm (b, a) * norm (b, c))) nan.0 where a = (1,0); b = (0,1); c = (1,2) norm ((x1, y1), (x2, y2)) = sqrt ((x1 - x2)^2 + (y1 - y2)^2) It /looks/ like a bug to me, but there may be some mysterious deep number magic I missed which explains this behaviour. -Adrian
Adrian Kubala wrote:
[...] Main> norm (b, a) * norm (b, c) 2.0
Well, mathematically this is 2, but not in Real-World-Floating-Point(tm) :-).
Main> asin (-2 / (norm (b, a) * norm (b, c)))
Again, in theory this is well defined: asin (-1) = -pi/2, but you actually don't pass -1, but something slightly smaller, so asin is undefined. See: http://docs.sun.com/htmlcoll/coll.648.2/iso-8859-1/NUMCOMPGD/ncg_goldberg.ht... Also note that "normal" Hugs versions only fake Double by using Float. So Hugs' behaviour is correct here... Cheers, S.
participants (3)
-
Adrian Kubala -
Alastair Reid -
Sven Panne