User Tools

Site Tools


numeric

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
numeric [2025/02/27 09:33] – created carlnumeric [2025/02/27 13:30] (current) carl
Line 1: Line 1:
 ====== Numeric Types ====== ====== Numeric Types ======
  
 +Numeric types represent [[https://en.wikipedia.org/wiki/Real_number|Real]] numbers in a computer.  Because computers have limited space, most numeric values are approximations of a real value.  
  
 Math in a computer is a combination of a storage of data, and a collection of operators.   Interpretation of the bits is up to the operators.  When we talk about a type of a number, we are usually referring to the operations we can do on them, rather than the storage. Math in a computer is a combination of a storage of data, and a collection of operators.   Interpretation of the bits is up to the operators.  When we talk about a type of a number, we are usually referring to the operations we can do on them, rather than the storage.
Line 7: Line 8:
  
   * Signed Integer (32 bits) - These usually have fast support in the processor.  Sometimes called an int.   * Signed Integer (32 bits) - These usually have fast support in the processor.  Sometimes called an int.
-    * Two's Complement - Represents Numbers as a string of bits.  Bit Vector addition results in (xor(N) + 1) + N = 0 +    * Two's Complement - Represents Numbers as a string of bits.  Bit Vector addition results in (inv(N) + 1) + N = 0 
-    * One's Complement - Represents Numbers as a string of bits.  Bit Vector addition results in (xor(N)) + N = 0+    * One's Complement - Represents Numbers as a string of bits.  Bit Vector addition results in (inv(N)) + N = 0
     * Signed Magnitude - Represents Numbers as one bit for the sign, and the remaining as an unsigned magnitude. N = (-1)^S x M     * Signed Magnitude - Represents Numbers as one bit for the sign, and the remaining as an unsigned magnitude. N = (-1)^S x M
   * Signed Integer (8 bits) - Sometimes called a byte.  Sometimes called an octet in the context of networking.   * Signed Integer (8 bits) - Sometimes called a byte.  Sometimes called an octet in the context of networking.
Line 33: Line 34:
  
  
 +As a consequence of their representation, most operations on numeric types are not true to their eponymous  mathematical function.  For example, adding two Int32 numbers can overflow, resulting in a wrong answer.  Also, most floating point operations are not associative: (a + b) + c != a + (b + c).  This is usually uncommon enough that it isn't a problem, but care should be taken to programming defensively.  
  
 +
 +
 +===== Support in Languages =====
 +
 +==== Java ====
 +Main: [[java:numeric|Java Numeric]].
  
numeric.1740677628.txt.gz · Last modified: by carl