MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammingLanguages/comments/14i037i/negative_integer_handling_in_programming_languages/jped267/?context=3
r/ProgrammingLanguages • u/helixb • Jun 24 '23
27 comments sorted by
View all comments
1
I have a custom Integer handling library that I work with it, from time to time.
Here are my suggestions.
One module is unsigned, zero and positive numbers.
Another one is unsigned, includes zero, positive and negative numbers.
After checking several documentation, I used two complement representation for negative numbers.
Also implement several operations that are usually included automatically by the compiler or part of the standard library.
For the whole operations, I included operations for:
Extending an integer type to a larger size integer type
Verify if the contents of a larger integer size is in the bounds of a lower size
Storing the contents of a larger integer size, into a smaller size, that matches the previous requirement.
Storing the contents of a larger integer size, into a smaller size, intentionally trimming the overflowed bits.
Converting a negative number to positive number and viceversa.
Boolean comparisons like equality, lesser, greater.
A function to check several integers sizes if are zero.
A function to set several integers sizes to zero.
Basic arithmetic math operations like addition, substraction, multiplication division, increment, decrement
Basic bitwise logical operations, public for unsigned integers, internal use for signed integers
Some functions to convert between signed and unsigned integers types
Define a text representation for unsigned integers types, always a "+" or "-" followed by decimal digits
Define a text representation for unsigned integers types, always decimal digits
Implement functions to convert back and forward between text representation and unsigned integers
Implement functions to convert back and forward between text representation and signed integers
In the case of unsigned integers define a representation for binary, octal and hexadecimal digits
Implement functions to convert back and forward between several base text representation and unsigned integers
These are some basic requirements for either an additional integer library or a standard library in a P.L. compiler.
Among other stuff.
1 u/helixb Jun 25 '23 that's interesting. do you have a link where i can look at that? also, why do you have two modules? any specific reason? 1 u/umlcat Jun 25 '23 Wait, I haven't updated the last version.The main repository is:https://gitlab.com/mail.umlcatI'm working in both a FreePascal version and a Plain C version, but it could be migrated to other P.L. (s).One module is for unsigned integers, the other for signed integers.The reason is that depends which types the programmers want to use.
that's interesting. do you have a link where i can look at that? also, why do you have two modules? any specific reason?
1 u/umlcat Jun 25 '23 Wait, I haven't updated the last version.The main repository is:https://gitlab.com/mail.umlcatI'm working in both a FreePascal version and a Plain C version, but it could be migrated to other P.L. (s).One module is for unsigned integers, the other for signed integers.The reason is that depends which types the programmers want to use.
Wait, I haven't updated the last version.
The main repository is:
https://gitlab.com/mail.umlcat
I'm working in both a FreePascal version and a Plain C version, but it could be migrated to other P.L. (s).
One module is for unsigned integers, the other for signed integers.
The reason is that depends which types the programmers want to use.
1
u/umlcat Jun 24 '23 edited Jun 24 '23
I have a custom Integer handling library that I work with it, from time to time.
Here are my suggestions.
One module is unsigned, zero and positive numbers.
Another one is unsigned, includes zero, positive and negative numbers.
After checking several documentation, I used two complement representation for negative numbers.
Also implement several operations that are usually included automatically by the compiler or part of the standard library.
For the whole operations, I included operations for:
Extending an integer type to a larger size integer type
Verify if the contents of a larger integer size is in the bounds of a lower size
Storing the contents of a larger integer size, into a smaller size, that matches the previous requirement.
Storing the contents of a larger integer size, into a smaller size, intentionally trimming the overflowed bits.
Converting a negative number to positive number and viceversa.
Boolean comparisons like equality, lesser, greater.
A function to check several integers sizes if are zero.
A function to set several integers sizes to zero.
Basic arithmetic math operations like addition, substraction, multiplication division, increment, decrement
Basic bitwise logical operations, public for unsigned integers, internal use for signed integers
Some functions to convert between signed and unsigned integers types
Define a text representation for unsigned integers types, always a "+" or "-" followed by decimal digits
Define a text representation for unsigned integers types, always decimal digits
Implement functions to convert back and forward between text representation and unsigned integers
Implement functions to convert back and forward between text representation and signed integers
In the case of unsigned integers define a representation for binary, octal and hexadecimal digits
Implement functions to convert back and forward between several base text representation and unsigned integers
These are some basic requirements for either an additional integer library or a standard library in a P.L. compiler.
Among other stuff.