Answer the question
In order to leave comments, you need to log in
Positional number systems?
In my project (C++, GUI in C#) I needed to work with different number systems (2,6,10,16 and more). And perform mathematical operations on them (addition, subtraction, multiplication, division). It is necessary to work with both natural and real numbers. And ideally, to get both the integer and the fractional parts in the form, for example, of a string, for display to users.
It is necessary to be able to call a function, for example, addition with two arguments: 1 is a natural number in the decimal system (2300), 2 is a real number in the ternary system (“2120.102”)
Are there such libraries (in C ++ or in C #), who could provide this functionality?
If there are none, wouldn't it be better to implement in some functional language (although most likely there already is) and link to C++ or C#?
Answer the question
In order to leave comments, you need to log in
You are mixing 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, these are numbers. There is a decimal system for writing numbers. (Ie speech about display).
If you correctly divide, then you will have - converters from string to numeric and vice versa, and the usual mathematical functions.
For example: create a class Number, add functions to it:
Number(<number_written_by_string>, <length>)
__toString(<length>)
And overloaded operators of addition, subtraction, division.
a couple of years ago I had fun with a similar thing (I wrote a calculator for myself), but I had to write the classes myself: I didn’t google anything similar.
True, I stored everything in the form of arrays (and the order, and the mantissa, and the base of the SS) and performed actions on them programmatically. It was clearly very slow. But it illustrated the work with different bases for number systems.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question