From 6355aef081693a098affe02422ceeff2449ce763 Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Fri, 10 Nov 2023 22:13:53 +0800 Subject: [PATCH] fix: many bugs --- src/utils.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/utils.cpp b/src/utils.cpp index 246ca1d..536dc1f 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -278,9 +278,13 @@ std::any Div(std::any a, std::any b) { throw InterpretException( "Div: string operation not allowed in this situation", 43); double t_a = Any2Float(a); + // std::cerr << t_a << std::endl; double t_b = Any2Float(b); + // std::cerr << t_b << std::endl; // if (t_b == 0) throw InterpretException("Div: divided by zero", 44); t_a = t_a / t_b; + // std::cerr << t_a << std::endl; + if (t_a > -1e-8 && t_a < 0) t_a = 0; return t_a; } std::any Divv(std::any a, std::any b) { @@ -296,17 +300,17 @@ std::any Divv(std::any a, std::any b) { double *ptr_a_float = std::any_cast(&a); double *ptr_b_float = std::any_cast(&b); if ((ptr_a_float != nullptr) && (ptr_b_float != nullptr)) { - if ((*ptr_b_float) == 0) - throw InterpretException("Divv: divided by zero", 45); - return ZYM::int2048(std::floor((*ptr_a_float) / (*ptr_b_float))); + // if ((*ptr_b_float) == 0) + // throw InterpretException("Divv: divided by zero", 45); + return ZYM::int2048(std::floor((*ptr_a_float) / (*ptr_b_float))); } else if ((ptr_a_int2048 != nullptr) && (ptr_b_int2048 != nullptr)) { if ((*ptr_b_int2048) == 0) - throw InterpretException("Divv: divided by zero", 46); - return (*ptr_a_int2048) / (*ptr_b_int2048); + // throw InterpretException("Divv: divided by zero", 46); + return (*ptr_a_int2048) / (*ptr_b_int2048); } else if ((ptr_a_bool != nullptr) && (ptr_b_bool != nullptr)) { if ((*ptr_b_bool) == 0) - throw InterpretException("Divv: divided by zero", 47); - return ZYM::int2048(int(*ptr_a_bool) / int(*ptr_b_bool)); + // throw InterpretException("Divv: divided by zero", 47); + return ZYM::int2048(int(*ptr_a_bool) / int(*ptr_b_bool)); } else throw FatalError("Divv: Type Error", 48); }