10
10
#include <coco.h>
11
11
#include "fp09.h"
12
12
13
- #if 1 /* Change to 0 to use single precision. */
13
+ /* Define SINGLE to use single precision */
14
+ #ifdef DOUBLE
14
15
typedef fp09_double Float ;
15
16
#define FLOAT_TYPE_ID fp09_double_type
16
17
#else
@@ -67,6 +68,7 @@ int main()
67
68
}
68
69
69
70
// wait for input
71
+ check_error ( & fpcb );
70
72
locate (31 ,0 );
71
73
x = waitkey (TRUE);
72
74
@@ -133,7 +135,6 @@ int main()
133
135
if ( blank == FALSE ) stack_input_buffer ();
134
136
fp09_FADD ( & fpcb , stack [1 ], stack [0 ], stack [0 ] );
135
137
move_stack_up ();
136
- check_error ( & fpcb );
137
138
}
138
139
else if (x == 'S' ) // Subtraction
139
140
{
@@ -144,7 +145,6 @@ int main()
144
145
fp09_FSUB ( & fpcb , stack [1 ], stack [0 ], stack [0 ] );
145
146
146
147
move_stack_up ();
147
- check_error ( & fpcb );
148
148
}
149
149
else if (x == 'M' ) // Multiply
150
150
{
@@ -155,7 +155,6 @@ int main()
155
155
fp09_FMUL ( & fpcb , stack [1 ], stack [0 ], stack [0 ] );
156
156
157
157
move_stack_up ();
158
- check_error ( & fpcb );
159
158
}
160
159
else if (x == 'D' ) // Divide
161
160
{
@@ -165,7 +164,6 @@ int main()
165
164
if ( blank == FALSE ) stack_input_buffer ();
166
165
fp09_FDIV ( & fpcb , stack [1 ], stack [0 ], stack [0 ] );
167
166
move_stack_up ();
168
- check_error ( & fpcb );
169
167
}
170
168
else if (x == 'O' )
171
169
{
@@ -192,7 +190,6 @@ int main()
192
190
193
191
if ( blank == FALSE ) stack_input_buffer ();
194
192
fp09_FSQRT ( & fpcb , stack [0 ], stack [0 ] );
195
- check_error ( & fpcb );
196
193
}
197
194
else if (x == 8 ) // delete key;
198
195
{
@@ -387,10 +384,6 @@ void stack_input_buffer()
387
384
printf ( " " );
388
385
389
386
}
390
- else
391
- {
392
- check_error ( & fpcb );
393
- }
394
387
}
395
388
396
389
void draw_stack ()
@@ -420,15 +413,24 @@ void move_stack_up()
420
413
421
414
void check_error ( fp09_FPCB * cb )
422
415
{
423
- locate (1 ,0 );
424
- printf ( "ERROR: " );
425
- if ( cb -> status & fp09_status_undefined ) printf ( "UNDEFINED " );
426
- if ( cb -> status & fp09_status_integer_overflow ) printf ( "INT OVERFLOW " );
427
- if ( cb -> status & fp09_status_unordered ) printf ( "UNORDERED " );
428
- if ( cb -> status & fp09_status_division_zero ) printf ( "DIV BY 0 " );
429
- if ( cb -> status & fp09_status_underflow ) printf ( "UNDERFLOW " );
430
- if ( cb -> status & fp09_status_overflow ) printf ( "OVERFLOW " );
431
- if ( cb -> status & fp09_status_invalid_operation ) printf ( "INVALID " );
416
+ locate (0 ,1 );
417
+ printf ( "ERROR: " );
418
+ if ( cb -> status == 0 )
419
+ {
420
+ printf ( "NONE\n" );
421
+ }
422
+ else
423
+ {
424
+ if ( cb -> status & fp09_status_inexact_result ) printf ( "INEXACT RESULT " );
425
+ if ( cb -> status & fp09_status_undefined ) printf ( "UNDEFINED " );
426
+ if ( cb -> status & fp09_status_integer_overflow ) printf ( "INT OVERFLOW " );
427
+ if ( cb -> status & fp09_status_unordered ) printf ( "UNORDERED " );
428
+ if ( cb -> status & fp09_status_division_zero ) printf ( "DIV BY 0 " );
429
+ if ( cb -> status & fp09_status_underflow ) printf ( "UNDERFLOW " );
430
+ if ( cb -> status & fp09_status_overflow ) printf ( "OVERFLOW " );
431
+ if ( cb -> status & fp09_status_invalid_operation ) printf ( "INVALID " );
432
+ printf ("\n" );
433
+ }
432
434
433
435
cb -> status = 0 ;
434
436
cb -> secondary_status = 0 ;
0 commit comments