## Can a IEEE 754 real number “cover” all integers within its range?

No, not all, but there exists a range within which you can represent all integers accurately. Structure of 32bit floating point numbers The 32bit floating point type uses 1 bit for the sign 8 bits for the exponent 23 bits for the fraction (leading 1 implied) Representing numbers Basically, you have a number in the … Read more

## How to calculate Tangent and Binormal?

The relevant input data to your problem are the texture coordinates. Tangent and Binormal are vectors locally parallel to the object’s surface. And in the case of normal mapping they’re describing the local orientation of the normal texture. So you have to calculate the direction (in the model’s space) in which the texturing vectors point. … Read more

## Fitting polynomials to data

Thanks for everyone’s replies. Here is another attempt at summarizing them. Pardon if I say too many “obvious” things: I knew nothing about least squares before, so everything was new to me. NOT polynomial interpolation Polynomial interpolation is fitting a polynomial of degree n given n+1 data points, e.g. finding a cubic that passes exactly … Read more

## Evaluating a string of simple mathematical expressions [closed]

Assembler 427 bytes Obfuscated, assembled with the excellent A86 into a .com executable: dd 0db9b1f89h, 081bee3h, 0e8af789h, 0d9080080h, 0bdac7674h, 013b40286h dd 07400463ah, 0ccfe4508h, 08ce9f675h, 02fc8000h, 013b0057eh, 0feaac42ah dd 0bedf75c9h, 0ba680081h, 04de801h, 04874f73bh, 04474103ch, 0e8e8b60fh dd 08e8a003fh, 0e880290h, 0de0153h, 08b57e6ebh, 0d902a93eh, 046d891dh dd 08906c783h, 05f02a93eh, 03cffcee8h, 057197510h, 02a93e8bh, 08b06ef83h dd 05d9046dh, 02a93e89h, 03bc9d95fh, 0ac0174f7h, 074f73bc3h, 0f3cac24h … Read more

## Code Golf: Mathematical expression evaluator (that respects PEMDAS)

C (465 characters) #define F for(i=0;P-8;i+=2) #define V t[i #define P V+1] #define S V+2]),K(&L,4),i-=2) #define L V-2] K(double*t,int i){for(*++t=4;*t-8;*++t=V])*++t=V];}M(double*t){int i,p,b; F if(!P)for(p=1,b=i;i+=2,p;)P?P-1||–p||(P=8,M(t+b+2),K(t+b,i-b),i=b):++p; F P-6||(L=pow(L,S;F P-2&&P-7||(L*=(P-7?V+2]:1/S;F P-4&&(L+=(P-5?V+2]:-S; F L=V];}E(char*s,char*r){double t[99];char*e,i=2,z=0;for(;*s;i+=2)V]= strtod(s,&e),P=z=e-s&&z-4&&z-1?s=e,4:*s++&7;P=8;M(t+2);sprintf(r,”%g”,*t);} The first five newlines are required, the rest are there just for readability. I’ve counted the first five newlines as one character each. If … Read more

## Is finding the equivalence of two functions undecidable?

Given an arbitrary function, f, we define a function f’ which returns 1 on input n if f halts on input n. Now, for some number x we define a function g which, on input n, returns 1 if n = x, and otherwise calls f'(n). If functional equivalence were decidable, then deciding whether g … Read more

## How to use 4d rotors

The most common way to represent goemetric algebra multivectors (including rotors) in a computer is via an array of coefficients, one for each canonical form algebra basis element (canonical basis blade) ie. for a 4D basis space you will have a 2^4 dimensional algebra and have 2^4 dimensional array of coefficients. An alternate but probably … Read more

## How do I detect intersections between a circle and any other circle in the same plane?

Two circles intersect if, and only if, the distance between their centers is between the sum and the difference of their radii. Given two circles (x0, y0, R0) and (x1, y1, R1), the formula is as follows: ABS(R0 – R1) <= SQRT((x0 – x1)^2 + (y0 – y1)^2) <= (R0 + R1) Squaring both sides … Read more

## How to map atan2() to degrees 0-360

Solution using Modulo A simple solution that catches all cases. degrees = (degrees + 360) % 360; // +360 for implementations where mod returns negative numbers Explanation Positive: 1 to 180 If you mod any positive number between 1 and 180 by 360, you will get the exact same number you put in. Mod here … Read more

## How to calculate an RGB colour by specifying an alpha blending amount?

The standard blending equation is: out = alpha * new + (1 – alpha) * old Where out, new and old are RGB colors, and alpha is a floating point number in the range [0,1]. So, you have (for red): 240 = 0.1 * newR + 0.9 * 255 Solving for newR, we get: newR … Read more