From cdff133ab8e8a0c9ec62586abc3729a14e1cbba5 Mon Sep 17 00:00:00 2001 From: Mistivia Date: Tue, 1 Jul 2025 01:30:40 +0800 Subject: fix div bug --- Makefile | 5 ++--- src/builtins.c | 2 +- tests/math.lisp | 2 ++ 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 47f92ce..06e4b38 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,6 @@ mode ?= debug cc = gcc includes = -DWITHREADLINE -I3rdparty/algds/build/include/ -#includes = -I3rdparty/algds/build/include/ 3rdlibs = 3rdparty/algds/build/lib/libalgds.a ldflags = -lm -lreadline @@ -10,8 +9,8 @@ ifeq ($(mode), debug) cflags = $(includes) \ -g \ -fsanitize=address -else ifeq ($(mode), debug) - cflags = $(includes) -g -flto -O2 +else + cflags = $(includes) -flto -O2 endif src = $(shell find src/ -name '*.c' -not -name 'main.c') diff --git a/src/builtins.c b/src/builtins.c index 9f605c1..f1c7d10 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -1220,7 +1220,7 @@ SExpRef builtin_div(Interp *interp, SExpRef args) { if (args_len == 1) { SExp num = *REF(CAR(args)); if (num.type == kIntegerSExp) { - return new_integer(interp, 1.0/num.integer); + return new_real(interp, 1.0/num.integer); } return new_real(interp, 1.0/num.real); } diff --git a/tests/math.lisp b/tests/math.lisp index cbd5298..4ecf876 100644 --- a/tests/math.lisp +++ b/tests/math.lisp @@ -9,6 +9,8 @@ (assert (= 1 (abs 1))) (assert (= 1.1 (abs 1.1))) +(~~ 0.2 (/ 5)) + (~~ 3.141 pi) (assert-error (~~ 3.2 pi)) -- cgit v1.0