#include <perms.h>

                                                                //      1  ! Print a floating point number out, along the lines of
                                                                //      2  ! +/-nnn.nnn@+/-nn, to occupy Places character spaces.
                                                                //      3  ! Note - there's a bug in this code such that it does not
                                                                //      4  ! round the number properly.  EG 3.999999999 to 4 places
                                                                //      5  ! should be 4.00 but we print 3.99
                                                                //      6  
                                                                //      7  %external %routine print(%longreal x, %integer places)
#line 7 "regression-bugs-tmp/print-abd.imp"
void PRINT( double X, int PLACES )
#line 7 "regression-bugs-tmp/print-abd.imp"
{
                                                                //      8     %integer exponent, digit, point, printexpo
#line 8 "regression-bugs-tmp/print-abd.imp"
int EXPONENT;
#line 8 "regression-bugs-tmp/print-abd.imp"
int DIGIT;
#line 8 "regression-bugs-tmp/print-abd.imp"
int POINT;
#line 8 "regression-bugs-tmp/print-abd.imp"
int PRINTEXPO;
                                                                //      9     !%externalintegerfnspec int pt(%real x)
                                                                //     10  
                                                                //     11     %if x = 0 %start
#line 11 "regression-bugs-tmp/print-abd.imp"
if (((X) != (0))) goto L_0002;
                                                                //     12        printstring("0.0")
#line 12 "regression-bugs-tmp/print-abd.imp"
_imp_PRINTSTRING(_imp_str_literal("0.0"));
                                                                //     13        %while places > 3 %cycle
#line 13 "regression-bugs-tmp/print-abd.imp"
L_0003:;
#line 13 "regression-bugs-tmp/print-abd.imp"
if (((PLACES) <= (3))) goto L_0004;
                                                                //     14           printsymbol('0')
#line 14 "regression-bugs-tmp/print-abd.imp"
_imp_PRINTSYMBOL(48);
                                                                //     15           places = places - 1
#line 15 "regression-bugs-tmp/print-abd.imp"
PLACES = (((int)(PLACES)) - (1));
                                                                //     16        %repeat
#line 16 "regression-bugs-tmp/print-abd.imp"
goto L_0003;
#line 16 "regression-bugs-tmp/print-abd.imp"
L_0004:;
                                                                //     17        %return
#line 17 "regression-bugs-tmp/print-abd.imp"
/* Remove %on %event handler here if present for this block */
return;
                                                                //     18     %finish
#line 18 "regression-bugs-tmp/print-abd.imp"
L_0002:;
                                                                //     19  
                                                                //     20     %if x < 0 %then printsymbol('-') %and x = -x %and places = places - 1
#line 20 "regression-bugs-tmp/print-abd.imp"
if (((X) >= (0))) goto L_0006;
#line 20 "regression-bugs-tmp/print-abd.imp"
_imp_PRINTSYMBOL(45);
#line 20 "regression-bugs-tmp/print-abd.imp"
X = (-(X));
#line 20 "regression-bugs-tmp/print-abd.imp"
PLACES = (((int)(PLACES)) - (1));
#line 20 "regression-bugs-tmp/print-abd.imp"
L_0006:;
                                                                //     21  
                                                                //     22     %if places < 3 %then places = 3
#line 22 "regression-bugs-tmp/print-abd.imp"
if (((PLACES) >= (3))) goto L_0007;
#line 22 "regression-bugs-tmp/print-abd.imp"
PLACES = 3;
#line 22 "regression-bugs-tmp/print-abd.imp"
L_0007:;
                                                                //     23     
                                                                //     24     exponent = 0
#line 24 "regression-bugs-tmp/print-abd.imp"
EXPONENT = 0;
                                                                //     25     printexpo = 0
#line 25 "regression-bugs-tmp/print-abd.imp"
PRINTEXPO = 0;
                                                                //     26  
                                                                //     27     %while x < 1 %cycle
#line 27 "regression-bugs-tmp/print-abd.imp"
L_0008:;
#line 27 "regression-bugs-tmp/print-abd.imp"
if (((X) >= (1))) goto L_0009;
/*promote*/                                                                //     28        x = x * 10
#line 28 "regression-bugs-tmp/print-abd.imp"
X = ((X) * ((double)(10)));
                                                                //     29        exponent = exponent - 1
#line 29 "regression-bugs-tmp/print-abd.imp"
EXPONENT = (((int)(EXPONENT)) - (1));
                                                                //     30     %repeat
#line 30 "regression-bugs-tmp/print-abd.imp"
goto L_0008;
#line 30 "regression-bugs-tmp/print-abd.imp"
L_0009:;
                                                                //     31  
                                                                //     32     %while x >= 10 %cycle
#line 32 "regression-bugs-tmp/print-abd.imp"
L_000b:;
#line 32 "regression-bugs-tmp/print-abd.imp"
if (((X) < (10))) goto L_000c;
                                                                //     33        x = x / 10
#line 33 "regression-bugs-tmp/print-abd.imp"
X = (double)((double)((double)(X)) / (double)((float)(10)));
                                                                //     34        exponent = exponent + 1
#line 34 "regression-bugs-tmp/print-abd.imp"
EXPONENT = (((int)(EXPONENT)) + (1));
                                                                //     35     %repeat
#line 35 "regression-bugs-tmp/print-abd.imp"
goto L_000b;
#line 35 "regression-bugs-tmp/print-abd.imp"
L_000c:;
                                                                //     36  
                                                                //     37     ! Now X is between 1.0 and 9.99 and exponent is set accordingly
                                                                //     38     ! If the exponent is "large" we will use scientific notation
                                                                //     39     point = places - 2;     ! for useful digits after the "0."
#line 39 "regression-bugs-tmp/print-abd.imp"
POINT = (((int)(PLACES)) - (2));
                                                                //     40     %if exponent >= places %or exponent < -point %start
#line 40 "regression-bugs-tmp/print-abd.imp"
if (((EXPONENT) >= (PLACES))) goto L_000d;
#line 40 "regression-bugs-tmp/print-abd.imp"
if (((EXPONENT) >= ((-(POINT))))) goto L_000e;
#line 40 "regression-bugs-tmp/print-abd.imp"
L_000d:;
                                                                //     41        printexpo = exponent
#line 41 "regression-bugs-tmp/print-abd.imp"
PRINTEXPO = EXPONENT;
                                                                //     42        exponent = 0
#line 42 "regression-bugs-tmp/print-abd.imp"
EXPONENT = 0;
                                                                //     43        places = places - 2
#line 43 "regression-bugs-tmp/print-abd.imp"
PLACES = (((int)(PLACES)) - (2));
                                                                //     44     %finish
#line 44 "regression-bugs-tmp/print-abd.imp"
L_000e:;
                                                                //     45  
                                                                //     46     ! Now the exponent is small-ish
                                                                //     47     %if exponent < 0 %start;      ! 0.nnnn
#line 47 "regression-bugs-tmp/print-abd.imp"
if (((EXPONENT) >= (0))) goto L_000f;
                                                                //     48        printsymbol('0'); printsymbol('.'); places = places - 2
#line 48 "regression-bugs-tmp/print-abd.imp"
_imp_PRINTSYMBOL(48);
#line 48 "regression-bugs-tmp/print-abd.imp"
_imp_PRINTSYMBOL(46);
#line 48 "regression-bugs-tmp/print-abd.imp"
PLACES = (((int)(PLACES)) - (2));
                                                                //     49        %while exponent < -1 %cycle
#line 49 "regression-bugs-tmp/print-abd.imp"
L_0010:;
#line 49 "regression-bugs-tmp/print-abd.imp"
if (((EXPONENT) >= ((-1)))) goto L_0011;
                                                                //     50           printsymbol('0')
#line 50 "regression-bugs-tmp/print-abd.imp"
_imp_PRINTSYMBOL(48);
                                                                //     51           exponent = exponent + 1
#line 51 "regression-bugs-tmp/print-abd.imp"
EXPONENT = (((int)(EXPONENT)) + (1));
                                                                //     52           places = places - 1
#line 52 "regression-bugs-tmp/print-abd.imp"
PLACES = (((int)(PLACES)) - (1));
                                                                //     53        %repeat
#line 53 "regression-bugs-tmp/print-abd.imp"
goto L_0010;
#line 53 "regression-bugs-tmp/print-abd.imp"
L_0011:;
                                                                //     54        point = -1; ! because we've already passed that
#line 54 "regression-bugs-tmp/print-abd.imp"
POINT = (-1);
                                                                //     55     %else;                        ! nnn.nnn
#line 55 "regression-bugs-tmp/print-abd.imp"
goto L_0013;
#line 55 "regression-bugs-tmp/print-abd.imp"
L_000f:;
                                                                //     56        point = exponent
#line 56 "regression-bugs-tmp/print-abd.imp"
POINT = EXPONENT;
                                                                //     57     %finish
#line 57 "regression-bugs-tmp/print-abd.imp"
L_0013:;
                                                                //     58  
                                                                //     59     %while places > 0 %cycle
#line 59 "regression-bugs-tmp/print-abd.imp"
L_0014:;
#line 59 "regression-bugs-tmp/print-abd.imp"
if (((PLACES) <= (0))) goto L_0015;
                                                                //     60        digit = int pt(x)
#line 60 "regression-bugs-tmp/print-abd.imp"
DIGIT = _imp_INTPT(X);
                                                                //     61        ! Rounding as we go through this loop can "oversize" the digit.  This
                                                                //     62        ! of course tells us that we should have printed (eg) 40000 but we
                                                                //     63        ! are now stuck with printing 39999
                                                                //     64        %if digit > 9 %then digit = 9
#line 64 "regression-bugs-tmp/print-abd.imp"
if (((DIGIT) <= (9))) goto L_0017;
#line 64 "regression-bugs-tmp/print-abd.imp"
DIGIT = 9;
#line 64 "regression-bugs-tmp/print-abd.imp"
L_0017:;
                                                                //     65        printsymbol(digit + '0')
#line 65 "regression-bugs-tmp/print-abd.imp"
_imp_PRINTSYMBOL((((int)(DIGIT)) + (48)));
/*promote*//*Warning: potential loss of precision converting from integer AST_ICONST (10 - 4 bytes) to real AST_BINOP (((X) - ((double)(DIGIT))) - 0 bytes) detected at ast.c line 108 */
                                                                //     66        x = (x - digit)*10
#line 66 "regression-bugs-tmp/print-abd.imp"
X = ((((X) - ((double)(DIGIT)))) * ((10)));
                                                                //     67        %if point = 0 %then printsymbol('.') %and places = places - 1
#line 67 "regression-bugs-tmp/print-abd.imp"
if (((POINT) != (0))) goto L_0018;
#line 67 "regression-bugs-tmp/print-abd.imp"
_imp_PRINTSYMBOL(46);
#line 67 "regression-bugs-tmp/print-abd.imp"
PLACES = (((int)(PLACES)) - (1));
#line 67 "regression-bugs-tmp/print-abd.imp"
L_0018:;
                                                                //     68        point = point - 1
#line 68 "regression-bugs-tmp/print-abd.imp"
POINT = (((int)(POINT)) - (1));
                                                                //     69        places = places - 1
#line 69 "regression-bugs-tmp/print-abd.imp"
PLACES = (((int)(PLACES)) - (1));
                                                                //     70     %repeat
#line 70 "regression-bugs-tmp/print-abd.imp"
goto L_0014;
#line 70 "regression-bugs-tmp/print-abd.imp"
L_0015:;
                                                                //     71  
                                                                //     72     %if printexpo # 0 %start
#line 72 "regression-bugs-tmp/print-abd.imp"
if (((PRINTEXPO) == (0))) goto L_0019;
                                                                //     73        printsymbol('@')
#line 73 "regression-bugs-tmp/print-abd.imp"
_imp_PRINTSYMBOL(64);
                                                                //     74        write(printexpo, 1)
#line 74 "regression-bugs-tmp/print-abd.imp"
_imp_WRITE(PRINTEXPO, 1);
                                                                //     75     %finish
#line 75 "regression-bugs-tmp/print-abd.imp"
L_0019:;
                                                                //     76  %end
#line 76 "regression-bugs-tmp/print-abd.imp"
/* Remove %on %event handler here if present for this block */
return;
} // End of block PRINT at level 1
                                                                //     77  
                                                                //     78  %begin
#line 78 "regression-bugs-tmp/print-abd.imp"
int main(int argc, char **argv) {
  _imp_initialise(argc, argv);
                                                                //     79  %end
#line 79 "regression-bugs-tmp/print-abd.imp"
/* Remove %on %event handler here if present for this block */
return 0;
} // End of block _imp_main at level 1
                                                                //     80  
                                                                //     81  %endoffile
#line 81 "regression-bugs-tmp/print-abd.imp"
// End of file
