Awesome q2a theme

Positional numeral systems

0 like 0 dislike
In my project (C++, GUI, C#) needed to work with different number systems (2,6,10,16 and not only). And to perform mathematical operations on them (addition, subtraction, multiplication, division). We have to work with natural and real numbers. And, ideally, to get the whole and fractional parts in the form of, for example, strings for displaying to users.

Need to be able to call functions, for example, addition with two arguments: 1 — a natural number in the decimal system (2300), 2 — real number in the ternary system ("2120.102")

Is there any library (in C++ or C#) that could provide this functionality?

If no, it would be better to implement in any functional language (although most likely already have) and link with C++ or C#?
by | 39 views

2 Answers

0 like 0 dislike
You mix logic with display. (And this is one of the greatest sins in programming)
There are no numbers in the decimal system or in the ternary system — numbers are numbers. Is the decimal system of writing numbers. (I.e. talking about the display).
If properly divided, then you will have converters from string to numeric entry and back, and the usual mathematical functions.
Example: create a class Number, add the functions:
Number(<Cieslak>, <the bit count>)
__toString(<the bit count>)
And overloaded operators for addition, subtraction, division.
0 like 0 dislike
a couple of years ago fun this thing (wrote their own calculator), but classes had to write himself: it is not googled anything like that.
However, I kept it all in an array (and the order and the mantissa, and the base CC) and operations on them performed by software. It was clearly very slow. But illustrated the work with different bases number systems.
110,608 questions
257,187 answers
40,796 users