# Tag Info

Accepted

### Will a computer attempt to divide by zero?

The CPU has built in detection. Most instruction set architectures specify that the CPU will trap to an exception handler for integer divide by zero (I don't think it cares if the dividend is zero). ...
Accepted

### Is it good practice to replace division with multiplication when possible?

Two common cases to consider: Integer arithmetic Obviously if you are using integer arithmetic (which truncates) you will get a different result. Here's a small example in C#: public static void ...
Accepted

### Why was the caret used for XOR instead of exponentiation?

Although there were older precursors, the influential French mathematician Rene Descartes is usually credited for introducing superscripted exponents (ab) into mathematical writing, in his work ...

### Why is Math.Sqrt() a static function?

Suppose we're designing a new language and we want Sqrt to be an instance method. So we look at the double class and begin designing. It obviously has no inputs (other than the instance) and returns ...
Accepted

### What is the size of the number 65535 in bytes?

TL;DR The key takeaway here is that there is a world of difference between the number 65535 and a piece of text which represents the digits '6', '5', '5', '3' and '5'. It may look the same to you when ...
Accepted

### Why does Math.min work with a one element array

According to MDN Math.min accepts only numbers, and if one of the arguments is not a number, it'll return NaN. That's not what it says (bold emphasis mine): If at least one of arguments cannot be ...

### What is the mathematics foundation for first/second/third class values in programming languages?

There isn't any, and it's pretty arbitrary. The only useful distinction is between first class, and all others. Every case that's in the "other" bracket has its own distinct set of rules in each case ...
Accepted

### Why is the norm of a complex number in the C++ complex library actually the square of the norm?

This is not a C++ library issue but a question of mathematical terminology. In mathematics, a norm can mean different things: What you call norm is the Euclidian norm, which is the distance to the ...

### Will a computer attempt to divide by zero?

It depends on the language, on the compiler, on whether you are using integers or floating point numbers, and so on. For floating point number, most implementations use the IEEE 754 standard, where ...

### Why is Math.Sqrt() a static function?

Mathematical operations are often very performance-sensitive. Therefore, we will want to use static methods that can be fully resolved (and optimizied, or inlined) at compile time. Some languages do ...

### Is it good practice to replace division with multiplication when possible?

I like your question as it potentially covers many ideas. On the whole, I suspect the answer is it depends, probably on the types involved and the possible range of values in your specific case. My ...

### Why is the norm of a complex number in the C++ complex library actually the square of the norm?

Christophe's post, whilst fully correct, does not actually answer the question why the terms look like they do. To give you definite answer for the reasons, you would have to ask someone from the C++...

### Is it good practice to replace division with multiplication when possible?

No. I'd probably call that premature optimization, in a broad sense, regardless of whether you're optimizing for performance, as the phrase generally refers to, or anything else that can be ...
Accepted

### Why is Math.Sqrt() a static function?

It is entirely a choice of language design. It also depends on the underlying implementation of primitive types, and performance considerations due to that. .NET has just one static Math.Sqrt method ...
Accepted

### Why do computer scientists seem to avoid closed-form solutions to mathematical problems?

Why do we implement Fibonacci numbers naively using its definition instead of using the explicit formula https://brilliant.org/discussions/thread/the-explicit-formula-for-fibonacci-sequence/. We don'...

### Why is Math.Sqrt() a static function?

I would be motivated by the fact that there's a ton of special-purpose math functions, and rather than populate every math type with all (or a random subset) of those functions you put them in a ...
Accepted

### Is it possible to store N bits of unique combinations, in N-1 bits? If not; why does MD5 get reprimanded for collissions?

Of course, the pigeonhole principle states that colisions are inevitable for hashing algorithms. The point of hashing algorithms is not to prevent colisions. But to make intentional collisions ...

### Will a computer attempt to divide by zero?

Seems like you're wondering what would happen if someone made a CPU that doesn't explicitly check for zero before dividing. What would happen depends entirely on the implementation of the division. ...

### Is it good practice to replace division with multiplication when possible?

Use whichever one is less buggy and makes more logical sense. Usually, division by a variable is a bad idea anyway, since usually, the divisor can be zero. Division by a constant is usually just ...
Accepted

### Swapping variable values without creating a new one

That is a longer and less efficient variant of XOR swap algorithm. I'll just reiterate most-commonly known solutions here from the wiki: # solution 1 A = A + B B = A - B A = A - B # solution 2 (^ is ...

### Interdependent variables

As you describe it, b is not a variable at all. Instead, it is a linear function of a. The solution is to create a method that computes the value for b from a and use it wherever you were going to ...
Accepted

### Convert version string to integer

No, there's no bulletproof way unless you know the maximum values in advance (the maximum number of digits per component). You will also need that information to decode the number. You're trying to ...
Accepted

### Storing a straight line equation

The equations can be all rewritten into form : a*X + b*Y + c = 0 That means you can store three doubles a, b and c. This doesn't have a problem in representing an arbitrary slope. You can also ...

### Convert version string to integer

If the only requirement is that each version string has a unique integer identifier, you can use a function like: int(x.y.z) = 2^x * 3^y * 5^z This is easily reversible by finding the prime ...
Accepted

### Smallest Rubik's cube state representation

You can encode the 8! possible permutations of the corners in 16 bits, and the 12! possible permutations in 29 bits, by numbering the permutations from 1 to 8! (or 1 to 12!), and storing the number. I ...
Accepted

### Integrating TeX into a Java desktop application

I have no experience with those specific libraries and tools, but since you asked this here on SE.SE, let me give you an answer on how to approach such an evaluation process as a software engineer. It ...

### What is the viability of engineering an integral type with values ranging from -1 to 254? Do types like this even exist?

You're taking the use specifically of -1 too literally here. APIs like this didn't really pick -1; they're either picking any negative number, or they're picking an integer with all of its bits set (...