-
Notifications
You must be signed in to change notification settings - Fork 9
Add expt #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add expt #26
Conversation
| base = SCM_INT_VALUE(_base); | ||
| expo = SCM_INT_VALUE(_expo); | ||
|
|
||
| if (expo < 0) ERR(ERRMSG_NEGATIVE_EXP); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a comment why we return an error here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done!
src/number.c
Outdated
| if (expo % 2 == 1) | ||
| result *= base; | ||
| base *= base; | ||
| expo /= 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use spaces instead of tabs for indent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, fixed!
|
Tests fail with However, I did (assert-error (tn) (expt 3 -2))which I suppose would work (?) |
Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
|
Thanks. |
It signals an error when the exponent is negative, since sigscheme only implements integer math.
This is an iterative implementation of exponentiation by squaring - and it works with negative bases.