# Tag Info

122

First off: I am a mathematician - a professional one (in that I get paid for doing maths). I am not a programmer. I do do some programming, but very definitely of the Cargo Cult variety (see first comment to http://tex.stackexchange.com/q/451/86 and my response) and nothing of the sort that would normally bring me to this site (indeed, I registered here to ...

82

I think it depends on what type of programming you want to do. As far as being a programmer in the business world goes, I would say that the answer is no. You can become a great programmer without knowing advanced mathematics. When you do end up having to deal with math, the formulas are usually defined in the business requirements so it only becomes a ...

67

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). It is possible that the check for a zero divisor happens in parallel in hardware along with the attempt to do the division, however, the detection of the ...

65

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 a double. We write and test the code. Perfection. But taking the square root of an integer is valid, too, and we don't want to force everyone to convert to ...

60

If you want a "math-like" language, Haskell is your best friend (for your best friend). You can easily make new functions without hassle. It is the best language recommendation I can give you for you friend. Here are some links: Try Haskell - An online Haskell compiler and tutorial. Learn You A Haskell For Great Good! - This is how I learned Haskell. How ...

59

Assuming that your square might be rotated against whatever coordinates system you have in place, you can't rely on there being any repetition of X and Y values in your four points. What you can do is calculate the distances between each of the four points. If you find the following to be true, you have a square: There are two points, say A and C which ...

55

I know this is an old post, but I saw this post being referenced and dislike the chosen answer's tone. So I did a bit of investigation! DirectX is old. It was first released in 1995, when the world had much more than Nvidia and ATI, DirectX vs OpenGL. That's over 15 years, people. 3dfx Interactive's Glide (one of DirectX's competitors back in the day. ...

55

The usual reason for writing numbers, in code, in other than base 10, is because you're bit-twiddling. To pick an example in C (because if C is good for anything, it's good for bit-twiddling), say some low-level format encodes a 2-bit and a 6-bit number in a byte: xx yyyyyy: main() { unsigned char codevalue = 0x94; // 10 010100 printf("x=%d, y=%d\n"...

53

There are many different fields of programming and many of those don't require a particularly high standard of mathematical knowledge. You will never be able to write a 3D engine, but you will certainly be able to develop business and web applications. Let's face it - the most common mathematical operation in most computer programmes is incrementing a number ...

47

You need to keep in mind that in FPU arithmetics, 0 doesn't necessarily has to mean exactly zero, but also value too small to be represented using given datatype, e.g. a = -1 / 1000000000000000000.0 a is too small to be represented correctly by float (32 bit), so it is "rounded" to -0. Now, let's say our computation continues: b = 1 / a Because a is ...

47

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 converted to a number, the result is NaN. Type Conversion: Math.min uses ToNumber to convert its arguments. ToNumber uses ToPrimitive to convert Objects (...

42

The main reason I use different bases is when I care about bits. It's much easier to read int mask=0xFF; byte bottom_byte = value & mask; than int mask=255; byte bottom_byte = value & mask; Or image something more complex int mask=0xFF00FF00; int top_bytes_by_word = value & mask; compared to int mask=4278255360; //can you say magic ...

37

The simplest solution would be to create a list where each element occurs as many times as its weight, so fruits = [apple, apple, apple, apple, orange, orange, lemon] Then use whatever functions you have at your disposal to pick a random element from that list (e.g. generate a random index within the proper range). This is of course not very memory ...

36

Your argumentation against floating point numbers is very fragile, probably because of naivety. (No offense here, I find your question is actually very interesting, I hope my answer will also be.) A classic argument is that floats provide a greater range, but high precision integers can meet this challenge now. For example: with modern 64-bit ...

33

2D / 1D - mapping is pretty simple. Given x and y, and 2D array sizes width and height, you can calculate the according index i in 1D space (zero-based) by i = x + width*y; and the reverse operation is x = i % width; // % is the "modulo operator", the remainder of i / width; y = i / width; // where "/" is an integer division You can extend this ...

33

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 division by 0 is well defined. 0 / 0 gives a well defined result of NaN (not-a-number), and x / 0 for x ≠ 0 gives either +Infinity or -Infinity, depending on ...

32

To really understand how arithmetic works inside a computer you need to have programmed in assembly language. Preferably one with a small word size and without multiplication and division instructions. Something like the 6502. On the 6502, virtually all arithmetic is done in a register called the Accumulator. (A register is a special memory location inside ...

32

The right thing to do in such circumstances is to implement the algorithm, formula or whatever with exactly the same variable names as in the primary real-world source (as far as the programming language allows this), and have a succinct comment above it saying something like "Levenshtein distance computation as described in [Knuth1968]", where the citation ...

30

I'm surprised nobody mentioned something: OpenGL works in a left-handed coordinate system too. At least, it does when you're working with shaders and use the default depth range. Once you throw out the fixed-function pipeline, you deal directly with "clip-space". The OpenGL Specification defines clip-space as a 4D homogeneous coordinate system. When you ...

30

You don't have to be good at math. However, you have to be good at logic, and problem solving. However people who are good at logic and problem solving are usually good at math also. I would say that it really depends on the type of math. You can be terrible at calculus (like me), and still be a good programmer (like me). But if you have trouble with ...

27

As a Computer Scientist looking to get a Master's degree with focus on "Algorithms, Complexity and Computability Theory and Programming Languages" I would say Discrete Mathematics is very important. Discrete math will help you with the "Algorithms, Complexity and Computability Theory" part of the focus more than programming language. The understanding of ...

26

They're not that closely related. For programming, it is important to know about mathematics- especially those branches pertaining to, for example, algorithm performance, but the simple fact is that there is no branch of mathematics that will tell you that Singletons are a horrifically bad idea, for example, or when to favour inheritance over composition, or ...

26

To simplify things by defining a concrete implementation, I will assume (as other answers do) that we're talking about IEEE 754 64-bit floating point. Each floating point number has three parts: a sign, an exponent, and a mantissa. (Technical details about hidden bits are irrelevant to this discussion). Reciprocation doesn't affect the sign 1 / (2**e * m) ...

26

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 not offer any mechanism to specify statically dispatched methods. Furthermore, the object model of many languages has considerable memory overhead that is ...

24

All programming is related to mathematics. Indeed many universities still place their computer science programs under the purview of the mathematics department. As for learning functional programming, you do not need to have a strong base in mathematics to learn it. I've learnt three different functional languages now to reasonable proficiency (Haskell, ...

24

I think this StackOverflow question answers it: http://stackoverflow.com/questions/4948780/magic-numbers-in-boosthash-combine Essentially, it is a "golden number" for hash functions, and it being an integer is quicker to calculate. The notation 0x is for a hexadecimal number, or base 16. The benefit of a base 16 number is that each pair of digits ...

24

Hmm, from what you say it seems you want to start very basic. Nothing bad about that, I did the same. My math was mostly high school level and a lot of it forgotten. Start with Khan Academy, go to the practice section and see how far you can get. This will give you a good idea what you can do and where to start learning. Don't bother watching the videos. ...

Only top voted, non community-wiki answers of a minimum length are eligible