Skip to content

Commit

Permalink
fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-develop committed Sep 4, 2024
1 parent 4215a53 commit d9892ac
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ Since 0.19.0-beta, we use [this changelog format](https://keepachangelog.com). I
## upcoming

### Fixed
* Fixed a crash in `math.log` on base=1

#### Build scripts
* Build scripts now copy `CHANGELOG.md`.
* `build.bat` is now more verbose.

### Calculator
#### Fixed
* Fixed a crash with `log` on base=1

## 1.1.0 (2024-08-13)

### Added
Expand Down
8 changes: 4 additions & 4 deletions examples/calculator.noug
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ while:main_loop True then
else
var calcul = input()
end

if calcul in ["exit", "exit()", "done", "quit", "q"] then break
if calcul == "" then continue
if calcul in ["clear", "cls"] then; clear(); continue; end
Expand Down Expand Up @@ -234,6 +234,8 @@ while:main_loop True then
replace(tokens, -1, "st")
elif char == "o" and len(tokens) > 0 and tokens(-1) == "st" then
replace(tokens, -1, "sto")
elif char == "g" and len(tokens) > 0 and tokens(-1) == "lo" then
replace(tokens, -1, "log")
elif char == "g" then
append(tokens, char)
elif char == "t" and len(tokens) > 0 and tokens(-1) == "gs" then
Expand All @@ -256,8 +258,6 @@ while:main_loop True then
append(tokens, char)
elif char == "o" and len(tokens) > 0 and tokens(-1) == "l" then
replace(tokens, -1, "lo")
elif char == "g" and len(tokens) > 0 and tokens(-1) == "lo" then
replace(tokens, -1, "log")
elif char == "n" and len(tokens) > 0 and tokens(-1) == "l" then
replace(tokens, -1, "ln")
elif char == "i" then
Expand Down Expand Up @@ -324,7 +324,7 @@ while:main_loop True then
elif token == "log" and len(stack) > 1 and is_num(stack(-1)) and is_num(stack(-2)) then
var number = stack(-2)
var base = stack(-1)
if number <= 0 or base <= 0 then
if number <= 0 or base <= 1 then
var error_msg = "Error: math domain error with logarithm"
print_error(error_msg, verbose)
var stack = list(old_stack)
Expand Down
9 changes: 8 additions & 1 deletion lib_/math_.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def copy(self):
"""Return a copy of self"""
copy = Math(self.name)
return self.set_context_and_pos_to_a_copy(copy)

def is_eq(self, other: Value):
return isinstance(other, Math) and self.name == other.name

Expand Down Expand Up @@ -479,6 +479,13 @@ def execute_math_log(self, exec_context: Context):
exec_context,
origin_file="lib_.math_.Math.execute_math_log"
))
except ZeroDivisionError as e:
return RTResult().failure(RTArithmeticError(
self.pos_start, self.pos_end,
"Python ZeroDivisionError: {e}",
exec_context,
origin_file="lib_.math_.Math.execute_math_log"
))

return RTResult().success(value_to_return)

Expand Down

0 comments on commit d9892ac

Please sign in to comment.