adding divide by 0 check in div
This commit is contained in:
		
							parent
							
								
									ae2a4dd156
								
							
						
					
					
						commit
						e365cb1d33
					
				| 
						 | 
					@ -1264,6 +1264,12 @@ int numeric_compare(value_t a, value_t b, int eq, int eqnans, char *fname)
 | 
				
			||||||
    return 1;
 | 
					    return 1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void DivideByZeroError() __attribute__ ((__noreturn__));
 | 
				
			||||||
 | 
					static void DivideByZeroError()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    lerror(DivideError, "/: division by zero");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static value_t fl_div2(value_t a, value_t b)
 | 
					static value_t fl_div2(value_t a, value_t b)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    double da, db;
 | 
					    double da, db;
 | 
				
			||||||
| 
						 | 
					@ -1280,7 +1286,7 @@ static value_t fl_div2(value_t a, value_t b)
 | 
				
			||||||
    db = conv_to_double(bptr, tb);
 | 
					    db = conv_to_double(bptr, tb);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (db == 0 && tb < T_FLOAT)  // exact 0
 | 
					    if (db == 0 && tb < T_FLOAT)  // exact 0
 | 
				
			||||||
        lerror(DivideError, "/: division by zero");
 | 
					        DivideByZeroError();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    da = da/db;
 | 
					    da = da/db;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1330,7 +1336,7 @@ static value_t fl_idiv2(value_t a, value_t b)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return return_from_int64(conv_to_int64(aptr, ta) / b64);
 | 
					    return return_from_int64(conv_to_int64(aptr, ta) / b64);
 | 
				
			||||||
 div_error:
 | 
					 div_error:
 | 
				
			||||||
    lerror(DivideError, "/: division by zero");
 | 
					    DivideByZeroError();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static value_t fl_bitwise_op(value_t a, value_t b, int opcode, char *fname)
 | 
					static value_t fl_bitwise_op(value_t a, value_t b, int opcode, char *fname)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1139,8 +1139,10 @@ static value_t apply_cl(uint32_t nargs)
 | 
				
			||||||
            goto next_op;
 | 
					            goto next_op;
 | 
				
			||||||
        case OP_IDIV:
 | 
					        case OP_IDIV:
 | 
				
			||||||
            v = Stack[SP-2]; e = Stack[SP-1];
 | 
					            v = Stack[SP-2]; e = Stack[SP-1];
 | 
				
			||||||
            if (bothfixnums(v, e))
 | 
					            if (bothfixnums(v, e)) {
 | 
				
			||||||
 | 
					                if (e==0) DivideByZeroError();
 | 
				
			||||||
                v = fixnum(numval(v) / numval(e));
 | 
					                v = fixnum(numval(v) / numval(e));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            else
 | 
					            else
 | 
				
			||||||
                v = fl_idiv2(v, e);
 | 
					                v = fl_idiv2(v, e);
 | 
				
			||||||
            POPN(1);
 | 
					            POPN(1);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1024,13 +1024,13 @@ new evaluator todo:
 | 
				
			||||||
* make (for ...) a special form
 | 
					* make (for ...) a special form
 | 
				
			||||||
* trycatch should require 2nd arg to be a lambda expression
 | 
					* trycatch should require 2nd arg to be a lambda expression
 | 
				
			||||||
* immediate load int8 instruction
 | 
					* immediate load int8 instruction
 | 
				
			||||||
- fix equal? on functions
 | 
					- maxstack calculation, make Stack growable
 | 
				
			||||||
- store function name and signature
 | 
					 | 
				
			||||||
- maxstack calculation, replace Stack with C stack, alloca
 | 
					 | 
				
			||||||
  - stack traces and better debugging support
 | 
					  - stack traces and better debugging support
 | 
				
			||||||
 | 
					- let eversion
 | 
				
			||||||
- lambda lifting
 | 
					- lambda lifting
 | 
				
			||||||
* let optimization
 | 
					* let optimization
 | 
				
			||||||
- let eversion
 | 
					- fix equal? on functions
 | 
				
			||||||
 | 
					- store function name and signature
 | 
				
			||||||
* have macroexpand use its own global syntax table
 | 
					* have macroexpand use its own global syntax table
 | 
				
			||||||
* be able to create/load an image file
 | 
					* be able to create/load an image file
 | 
				
			||||||
* fix trace and untrace
 | 
					* fix trace and untrace
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue