To begin looking at SPU assembly language, I will enter in a simple program for calculating the factorial of a 32-bit number using a recursive algorithm.
在开始介绍SPU汇编语言之前,先来看一个通过递归算法计算32 位数的阶乘的简单程序。
Since factorials of numbers less than 1 don't make any sense, we stop at the number 1 and return the factorial of 1 (which is 1). Therefore, the real factorial function will look like this
由于小于1的数的阶乘没有任何意义,所以我们在计算到数字 1 的时候停止,并返回 1的阶乘(即 1)。
The factorial of a number is computed as that number times all of the Numbers below it up to and including 1.
计算某个数的阶乘就是用那个数去乘包括1在内的所有比它小的数。
We did the factorial function earlier and it's the product of a number and the factorial of that number minus one.
早些时候我们编写过一个计算fibtorial数的函数它便是某数与它减一的factorial数的积.
These results evaluate to infinity, as the number returned by a 10,000,000 factorial is too large for a double-precision variable to contain.
估计这些结果会无限大,因为10,000,000的阶乘返回的数字对于双精度变量而言太大,以至超出了它包含的范围。
An interesting property of a factorial is that the factorial of a number is equal to the starting number multiplied by the factorial of the number immediately below it.
阶乘的一个有趣特性是,某个数的阶乘等于起始数(startingnumber)乘以比它小一的数的阶乘。
An interesting property of a factorial is that the factorial of a number is equal to the starting number multiplied by the factorial of the number immediately below it.
阶乘的一个有趣特性是,某个数的阶乘等于起始数(startingnumber)乘以比它小一的数的阶乘。
应用推荐