big: Add tests for log.

This commit is contained in:
Jeroen van Rijn
2021-08-11 20:59:52 +02:00
parent 922df6a438
commit 385b9c9922
4 changed files with 123 additions and 79 deletions
+28 -1
View File
@@ -95,4 +95,31 @@ PyRes :: struct {
r, err = int_itoa_cstring(quotient, i8(radix), context.temp_allocator);
if err != .None { return PyRes{res=":div_two:itoa(quotient):", err=err}; }
return PyRes{res = r, err = .None};
}
}
/*
res = log(a, base)
*/
@export test_log :: proc "c" (a: cstring, base := DIGIT(2), radix := int(10)) -> (res: PyRes) {
context = runtime.default_context();
err: Error;
l: int;
aa := &Int{};
defer destroy(aa);
if err = atoi(aa, string(a), i8(radix)); err != .None { return PyRes{res=":log:atoi(a):", err=err}; }
if l, err = log(aa, base); err != .None { return PyRes{res=":log:log(a, base):", err=err}; }
zero(aa);
aa.digit[0] = DIGIT(l) & _MASK;
aa.digit[1] = DIGIT(l) >> _DIGIT_BITS;
aa.used = 2;
clamp(aa);
r: cstring;
r, err = int_itoa_cstring(aa, i8(radix), context.temp_allocator);
if err != .None { return PyRes{res=":log:itoa(res):", err=err}; }
return PyRes{res = r, err = .None};
}