96 kHz.org
Advanced Audio Recording

Generation of special numbers in C and ASM

This page describes various numbers to make calculations easier. In digital systems, division and exponentiatials are difficult and time-consuming. Therefore, simple combinations of numbers are often easier to work with. The idea behind this is to scale the local calculation with a shortend number or even a binary number. Possibly it makes sense to scale a greater part of the whole calculation and rescale it afterwards. This can siginificantly increase speed.

 

Tuning word

A most simple relation between two adjecent notes in a music keyboard had been found trying around with VC20 in the 80-tees:

f ( "Cis") / f (" C ") =  196 / 185

This works for a whole octave and raises only some parts per million of deviation.

 

PI and 1/ PI

Pi is an important mathematical constant. It not only describes the ratio of a circle’s circumference to its diameter – it is also used to calculate the volume of spheres and cylinders. In physics, pi features in waves, oscillations and probability theory. PI ist often required to fit sine waves. The table shows binary combinations as well as standard INTs for both PI and 1/PI. Many people go for 22/7. The best number I found was 355/113. It has only 0,1 ppm deviation.

 

mul div div bits PI* rel / ppm
3217 1024 10 3,141601563 2,83579
205887 65536 16 3,141586304 -2,02123
411775 131072 17 3,141593933 0,40728
1647099 524288 19 3,141592026 -0,19985
3294199 1048576 20 3,141592979 0,10372
355 113 3,141592920 0,08491
63878 20333 3,141592485 -0,05362
6588397 2097152 21 3,141592503 -0,04806
13176795 4194304 22 3,141592741 0,02783
26353589 8388608 23 3,141592622 -0,01012
94053 29938 3,141592625 -0,00918
52707179 16777216 24 3,141592681 0,00885
105414357 33554432 25 3,141592652 -0,00063
1686629713 536870912 29 3,141592653 -0,00004
mul div div bits 1 / PI* rel / ppm
20861 65536 16 0,318313599 11,66300
83443 262144 18 0,318309784 -1,00915
113 355 0,318309859 -0,26676
2670177 8388608 23 0,318309903 0,16740
20333 63878 16 0,318309903 0,16847
10680707 33554432 25 0,318309873 -0,12674
29938 94053 0,318309889 0,02883
21361415 67108864 0,318309888 0,02033
85445659 268435456 28 0,318309885 -0,01644
170891319 536870912 29 0,318309886 0,00195

 

Eulers number

 Euler’s number "e" is one of the most important constants in mathematics. It describes the principle of continuous, self identical growth and decay and is the basis for the natural exponential function. It describes a number of decay processes and is required for oscillator calculations. Binary representations work pretty good.

 

mul div div bits e rel / ppm
178145 65536 16 2,7182769775 -1,784550
356291 131072 17 2,7182846069 1,022147
712581 262144 18 2,7182807922 -0,381202
1425163 524288 19 2,7182826996 0,320473
2850325 1048576 20 2,7182817459 -0,030365
22802601 8388608 23 2,7182818651 0,013490
45605201 16777216 24 2,7182818055 -0,008437
91210403 33554432 25 2,7182818353 0,002526
182420806 67108864 26 2,7182818353 0,002526
364841611 134217728 27 2,7182818279 -0,000214
2918732889 1073741824 30 2,7182818288 0,000128
5837465777 2147483648 31 2,7182818283 -0,000043
11674931555 4294967296 32 2,7182818286 0,000042
23349863109 8589934592 33 2,7182818284 0,000000

 

sqrt (2)
 

 The number √2 describes, geometrically, the diagonals of a square. In electrical engineering, it is the ratio of the peak value of an alternating voltage to its root mean square value.

mul div div bits sqrt(2) rel / ppm
11585 8192 13 1,414184570 -20,5004826
46341 32768 15 1,414215088 1,0787038
741455 524288 19 1,414213181 -0,2699954
2965821 2097152 21 1,414213657 0,0671794
11863283 8388608 23 1,414213538 -0,0171143
47453133 33554432 25 1,414213568 0,0039592
189812531 134217728 27 1,414213561 -0,0013092
759250125 536870912 29 1,414213562 0,0000079
1451 1026 1,414230019 11,6369412
1492 1055 1,414218009 3,1445785
1632 1154 1,414211438 -1,5018228
1731 1224 1,414215686 1,5018251
1970 1393 1,414213927 0,2576723


sqrt (3)

The cube root comes into play when calculating the height of an equilateral triangle or the distance between opposite sides of a hexagon. In electrical engineering, it is required in three-phase alternating current networks, where it acts as the conversion factor between line-to-line voltage and phase-to-phase voltage.
 

mul div div bits sqrt(3) rel / ppm
14189 8192 13 1,7320556641 2,803898
227023 131072 17 1,7320480347 -1,600935
454047 262144 18 1,7320518494 0,601481
908093 524288 19 1,7320499420 -0,499727
1816187 1048576 20 1,7320508957 0,050877
14529495 8388608 23 1,7320507765 -0,017948
29058991 16777216 24 1,7320508361 0,016465
58117981 33554432 25 1,7320508063 -0,000742
929887697 536870912 29 1,7320508081 0,000334
1859775393 1073741824 30 1,7320508072 -0,000204
3719550787 2147483648 31 1,7320508077 0,000065
mul div div bits sqrt(3) rel / ppm
1978 1142 1,7320490368 -1,022367
2340 1351 1,7320503331 -0,273942
3691 2131 1,7320506804 -0,073403
5042 2911 1,7320508416 0,019668

 

more to come ...

 

 

 

© 2001 - Jürgen Schuhmacher