[comp.lang.c] MATH Error in MS C 5.0

jap7g@psy3b2.psyc.Virginia.EDU (Jim A. Pisano) (04/06/88)

I'm writing a simple program that times keypresses using MicroSoft C V 5.0.
The times are obtained using the 'ftime()' functions.  I then convert the
times (in integer form) to floating point #'s (doubles) & display the 
times of keypresses & elapsed time between presses.
After the program runs (it runs correctly), I get the error:

run-time error M6101:  MATH
- floating-point error: invalid

The manual says that I tried to calculate infinity (I already know what
infinity is) or I operated on a NAN (Not A Number).

Here's my question: How can I find out where that NAN is?  I have CodeView,
but I haven't figured out how to trap this math error short of checking 
every variable everywhere.  Is there a way to set a tracepoint when the
math emulator is used?

Thanks,

Jim Pisano         Psychology Department   University of Virginia
jap7g@virginia

jap7g@psy3b2.psyc.Virginia.EDU (Jim A. Pisano) (04/06/88)

   I've written a simple keyboard-timing program in Microsoft C Ver. 5.0
which records when a keypress is made & the elapsed time between keypresses
in a given time period. I use the function 'ftime()' to get hours, minutes,
seconds, & milliseconds.  These times are then converted to  decimal hours
(I use doubles).
	Here's the problem:  The program runs fine, i.e. it calculates all of the
times & elapsed times correctly for the given time period, prints out the
results, & displays the message:
				run-time error M6101: MATH
				- floating-point error: invalid

The manual says that error M6101 results when an invalid operation occured.
This usually involves operating on a NAN (Not A Number) or infinity.  It
exits at that point with exit code 127.
	I've used Codeview without success on the routine that uses floating point
math & Codeview says that the program terminates normally with exit code 127.

Here are my questions: Can someone recognize this problem?  Where could it be
coming from? I have an 80287-equiped AT & have looked at the 80287 registers
with the '7' command, but I don't know enough about the 80287 to debug my
problem.

Please reply by e-mail, as I don't read comp.lang.c regularly.

Thanks in advance,

Jim Pisano

greg@csanta.UUCP (Greg Comeau) (04/09/88)

In article <734@virginia.acc.virginia.edu> jap7g@psy3b2.psyc.Virginia.EDU (Jim A. Pisano) writes:
>I get the error:
>run-time error M6101:  MATH
>- floating-point error: invalid
>
>Here's my question: How can I find out where that NAN is?  I have CodeView,
>but I haven't figured out how to trap this math error short of checking 
>every variable everywhere.  Is there a way to set a tracepoint when the

You might be able to find out by using the signal() function so that
it traps SIGFPE and jumps to one of your routines.