32
votes
Accepted
What are the advantages and disadvantages of implementing reals as rationals?
Floating-point vs rational representation
Advantages of rational representation:
Precision: rational numbers are exact. 1/7 prints as ...
30
votes
What are the drawbacks of allowing implicit boolean/integer conversions?
The main drawback of allowing implicit boolean/integer conversions is, it makes it impossible to prevent errors that result from confusion of a boolean and an integer.
Next time you confuse the order ...
29
votes
Accepted
What are some advantages/disadvantages of having built-in syntax to represent numbers in non-decimal bases?
One advantage is bitwise arithmetic. Bitwise arithmetic is much easier to understand in bases with a power of 2 radix such as hexadecimal. Here it is fairly clear that I am masking out every other ...
24
votes
Accepted
What are the drawbacks of allowing implicit boolean/integer conversions?
There is a particular drawback of allowing implicit conversions (aka coercions*) from bool to int in dynamic languages such as ...
19
votes
What are some advantages/disadvantages of having built-in syntax to represent numbers in non-decimal bases?
In a domain where a specific base is used, it is clearer if the code can reflect this and still be efficient.
For example, airplane transponders use base 8, and colours are often represented in base ...
14
votes
What are the disadvantages of not handling big numbers?
Applications of "big numbers"
The last paragraph of my answer to Did the 2019 discovery of O(N log(N)) multiplication have a practical outcome? gives some examples of cases in which large ...
13
votes
Accepted
What are the disadvantages of this far-fetched idea: All integers can be treated as boolean arrays?
I wouldn't store them as arrays, but you can certainly implement such a syntax efficiently. If you translate x[0] to x & 1 ...
9
votes
What are the disadvantages of not handling big numbers?
The question asks a double negative, so I'll answer the simpler question of what advantages there are to supporting big numbers.
To me, the main benefit is peace of mind ─ sure, my auto-incrementing ...
9
votes
What are some advantages/disadvantages of having built-in syntax to represent numbers in non-decimal bases?
The other answers so far have exclusively focused on advantages. There are two disadvantages I can think of, though neither is really a strong enough reason to exclude this feature from a language.
...
9
votes
What are the pros and cons of fixed-point arithmetics vs floating-point arithmetics?
The main upside of floating-point arithmetic is that it allows for reprensenting a wider range of magnitudes than a fixed-point number using the same number of bits, while also allowing for more ...
9
votes
What are the drawbacks of allowing implicit boolean/integer conversions?
Booleans may not just be 1 or 0
Much of this depends on the underlying representation of the value. My particular experience of this is with C.
Before C99, there was no boolean type, only integers ...
8
votes
What are the disadvantages of this far-fetched idea: All integers can be treated as boolean arrays?
It would encourage inefficient code
90% of the time when you're doing individual bit lookups on an int, you're doing something "wrong". E.g., this would encourage those who don't feel ...
8
votes
What are the disadvantages of not handling big numbers?
"Super common" is a relative thing; I don't often use large numbers in my code, but I know people who do. It mostly depends on what your language is meant to be used for; tiny esoteric ...
8
votes
What are the disadvantages of not handling big numbers?
Actual high-magnitude numbers aren't usually needed, but precision is much more often an issue, and the two often go together.
For example, using 64-bit floats to represent money amounts can quickly ...
8
votes
What are the advantages and disadvantages of implementing reals as rationals?
I am implementing a language that uses rationals by default. Let me tell you why.
The other answers are correct that performance and memory use are worse with rationals. My rationals are 32 bytes ...
8
votes
What are the drawbacks of allowing implicit boolean/integer conversions?
In addition to all the other fine answers, Boolean coercions are not consistent across languages:
Zero (0) is considered falsy in Python and JavaScript, but truthy ...
7
votes
What are the advantages and disadvantages of implementing reals as rationals?
Why not both?
That is, make your “real” type a variant that can store either an exact rational or an approximate floating point value.
You could make rational the “default”, in that literal ...
7
votes
What are some advantages/disadvantages of having built-in syntax to represent numbers in non-decimal bases?
Runtime safety
With syntax like 0x1A50 instead of parseInt("1A50",16) you can make sure at compile time that ...
6
votes
What are the disadvantages of this far-fetched idea: All integers can be treated as boolean arrays?
Strictly speaking, an "array" is a specific kind of data structure where elements are stored at contiguous, equally-spaced memory addresses. The smallest addressable unit of memory is ...
6
votes
What are the downsides of having types for floats and integers?
The main advantage of having a number type is simplicity and ease of use. Many versions of BASIC just had floating point numbers, which reduced the size of the code (given that the first home computer,...
6
votes
Accepted
What are the downsides of having types for floats and integers?
It's not a common case, but integral data types (sometimes known as shorts and longs) allow for integer overflow, which may be used by clever programmers (if the programming language allows it). E.g. ...
6
votes
What are the disadvantages of not handling big numbers?
Almost none
Most major programming languages, like C#, Java and as you mentioned, JavaScript, don't support arbitrary large integers in their default namespaces/packages/... However, for all of those ...
6
votes
What are the pros and cons of fixed-point arithmetics vs floating-point arithmetics?
Fixed point arithmetic is more consistent
Adding 0.128 to a number will always add 0.128 to the number until you reach the limit.
In floating point arithmetic the steps get more inconsistent the ...
6
votes
What are the pros and cons of fixed-point arithmetics vs floating-point arithmetics?
Firstly, consider fixed-point decimal arithmetic vs. fixed of floating point binary: the former is suitable for precise representation of monetary values, while the latter shall never be used for such....
6
votes
How could fixed-point be implemented?
Fixed-point is an integer with a statically-known decimal (or more generally, statically-known divisor). You can represent a fixed-point datatype as an "representation" integer type and &...
6
votes
What are the drawbacks of allowing implicit boolean/integer conversions?
One particularly bad issue with int to bool conversions is that if you have an expression based language, the assignment x=7 will typically return ...
5
votes
What are the downsides of having types for floats and integers?
The problem with having only a single number type is: which number type do you pick?
For a good example of what not to do, you have to look no further than the most widely-used (depending on ...
5
votes
What are the advantages and disadvantages of implementing reals as rationals?
Advantages
Rationals can exactly represent a much wider range of numbers. One-third would be finitely representable.
Floating point errors would be unheard of.
Disadvantages
It is computationally ...
5
votes
What are the disadvantages of this far-fetched idea: All integers can be treated as boolean arrays?
It privileges one form of bit access over others
Accessing a word as a bit vector can be useful in some circumstances, but even more useful is the ability to pack and unpack general bit fields. Things ...
5
votes
How could fixed-point be implemented?
Make precision part of the type
I’m not familiar with any general-purpose languages that use fixed point at all, but this is what PostgreSQL does. If you want to indicate that a column stores 15 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
numbers × 11syntax × 2
language-design × 2
integers × 2
fixed-point × 2
floating-point × 2
booleans × 2
implementation × 1
operators × 1
c × 1
optimization × 1
arrays × 1
strings × 1
c++ × 1
math × 1
data-types × 1
bitwise-operators × 1
type-conversion × 1