Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédente | |||
back2root:archives:denthor:part-06 [2021/09/05 13:55] – [In closing] frater | back2root:archives:denthor:part-06 [2024/08/27 08:55] (Version actuelle) – [How do I generate a lookup table?] frater | ||
---|---|---|---|
Ligne 31: | Ligne 31: | ||
One way of looking at a lookup table is as follows : Let us say that for some obscure reason you need to calculate a lot of multiplications (eg. 5*5 , 7*4 , 9*2 etc.). Instead of actually doing a slow multiply each time, you can generate a kind of bonds table, as seen below : | One way of looking at a lookup table is as follows : Let us say that for some obscure reason you need to calculate a lot of multiplications (eg. 5*5 , 7*4 , 9*2 etc.). Instead of actually doing a slow multiply each time, you can generate a kind of bonds table, as seen below : | ||
+ | {{tablelayout? | ||
+ | ^ X ^ 1 ^ 2 | ||
+ | ^ 1 | 1 | 2 | ||
+ | ^ 2 | 2 | 4 | ||
+ | ^ 3 | 3 | 6 | ||
+ | ^ 4 | 4 | 8 | ||
+ | ^ 5 | 5 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | | ||
+ | ^ 6 | 6 | 12 | 18 | 24 | 30 | 36 | 42 | 48 | 54 | | ||
+ | ^ 7 | 7 | 14 | 21 | 28 | 35 | 42 | 49 | 56 | 63 | | ||
+ | ^ 8 | 8 | 16 | 24 | 32 | 40 | 48 | 56 | 64 | 72 | | ||
+ | ^ 9 | 9 | 18 | 27 | 36 | 45 | 54 | 63 | 72 | 81 | | ||
+ | |||
- | < | ||
- | ╔═Đ═╦═══════Đ══════Đ══════Đ══════Đ══════Đ══════Đ══════Đ══════Đ══════╗ | ||
- | ă─┼─Â | ||
- | ă─┴─Î═══════ě══════ě══════ě══════ě══════ě══════ě══════ě══════ě══════Á | ||
- | ║ 1 ║ | ||
- | ă───Î───────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤ | ||
- | ║ 2 ║ | ||
- | ă───Î───────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤ | ||
- | ║ 3 ║ | ||
- | ă───Î───────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤ | ||
- | ║ 4 ║ | ||
- | ă───Î───────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤ | ||
- | ║ 5 ║ | ||
- | ă───Î───────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤ | ||
- | ║ 6 ║ | ||
- | ă───Î───────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤ | ||
- | ║ 7 ║ | ||
- | ă───Î───────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤ | ||
- | ║ 8 ║ | ||
- | ă───Î───────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤ | ||
- | ║ 9 ║ | ||
- | ╚═══╩───────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┘ | ||
- | </ | ||
This means that instead of calculating 9*4, you just find the 9 on the top and the 4 on the side, and the resulting number is the answer. This type of table is very useful when the equations are very long to do. | This means that instead of calculating 9*4, you just find the 9 on the top and the 4 on the side, and the resulting number is the answer. This type of table is very useful when the equations are very long to do. | ||
- | The example I am going to use for this part is that of circles. Cast your minds back to Part 3 on lines and circles. The circle section took quite a while to finish drawing, mainly because I had to calculate the SIN and COS for EVERY SINGLE POINT. Calculating SIN and COS is obviously very slow, and that was reflected in the speed of the section. | + | The example I am going to use for this part is that of circles. Cast your minds back to [[back2root: |
==== How do I generate a lookup table? ==== | ==== How do I generate a lookup table? ==== | ||
Ligne 72: | Ligne 61: | ||
Then in the program we get the memory for these two pointers. Asphyxia was originally thinking of calling itself Creative Reboot Inc., mainly because we always forgot to get the necessary memory for our pointers. | Then in the program we get the memory for these two pointers. Asphyxia was originally thinking of calling itself Creative Reboot Inc., mainly because we always forgot to get the necessary memory for our pointers. | ||
+ | |||
(Though a bit of creative assembly coding also contributed to this. We wound up rating our reboots on a scale of 1 to 10 ;-)). | (Though a bit of creative assembly coding also contributed to this. We wound up rating our reboots on a scale of 1 to 10 ;-)). | ||
- | The next obvious step is to place our necessary answers into our lookup tables. This can | + | The next obvious step is to place our necessary answers into our lookup tables. This can take a bit of time, so in a demo, you would do it in the very beginning (people just think it's slow disk access or something), or after you have shown a picture (while the viewer is admiring it, you are calculating pi to its 37th degree in the background ;-)) |
- | take a bit of time, so in a demo, you would do it in the very beginning (people just think it's slow disk access or something), or after you have shown a picture (while the viewer is admiring it, you are calculating pi to its 37th degree in the background ;-)) | + | |
Another way of doing it is, after calculating it once, you save it to a file which you then load into the variable at the beginning of the program. Anyway, this is how we will calculate the table for our circle : | Another way of doing it is, after calculating it once, you save it to a file which you then load into the variable at the beginning of the program. Anyway, this is how we will calculate the table for our circle : |