Skip to content

Commit df2a7fb

Browse files
committed
Add decimal option to bindings
1 parent 768ae5d commit df2a7fb

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

lib/bindings.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,18 @@ NB_MODULE(steppyble, mod) // NOLINT
111111
"Internal function that subtracts two numbers.");
112112
internals.def(
113113
"multiply",
114-
[](const std::string& a, const std::string& b, const int steps) { return multiply(a, b, steps); },
114+
[](const std::string& a, const std::string& b, const int steps, const int decimals) {
115+
return multiply(a, b, steps, decimals);
116+
},
115117
"a"_a,
116118
"b"_a,
117119
"steps"_a = 2,
120+
"decimals"_a = 8,
118121
"Internal function that multiplies two numbers.");
119122
internals.def(
120123
"divide",
121124
[](const std::string& a, const std::string& b, const int steps, const int decimals) {
122-
return divide(a, b, steps);
125+
return divide(a, b, steps, decimals);
123126
},
124127
"a"_a,
125128
"b"_a,
@@ -129,5 +132,11 @@ NB_MODULE(steppyble, mod) // NOLINT
129132
internals.def("divideWithQuotient",
130133
&divideWithQuotient,
131134
"Internal function that divides two numbers, but separating the quotient and remainder.");
132-
internals.def("power", &power, "a"_a, "raiseTo"_a, "steps"_a = 2, "Internal function raises a number to a power.");
135+
internals.def("power",
136+
&power,
137+
"a"_a,
138+
"raiseTo"_a,
139+
"steps"_a = 2,
140+
"decimals"_a = 8,
141+
"Internal function raises a number to a power.");
133142
}

src/calc/power/power.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,13 @@ int main(const int _argc, const char* _argv[])
151151
const auto& aStr = program.getPosArg(0);
152152
const auto& bStr = program.getPosArg(1);
153153

154+
#if DEBUG
154155
if (steps == 475)
155156
{
156-
std::cout << steppable::__internals::calc::exp(aStr, decimals) << std::endl;
157+
std::cout << steppable::__internals::calc::exp(aStr, decimals) << '\n';
157158
return 0;
158159
}
160+
#endif
159161

160162
if (profile)
161163
{

src/number.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ namespace steppable
7777

7878
Number Number::operator%(const Number& rhs) const { return divideWithQuotient(value, rhs.value).remainder; }
7979

80-
Number Number::operator^(const Number& rhs) const { return power(value, rhs.value, 0); }
80+
Number Number::operator^(const Number& rhs) const { return power(value, rhs.value, 0, static_cast<int>(prec)); }
8181

8282
Number& Number::operator+=(const Number& rhs)
8383
{

0 commit comments

Comments
 (0)