Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
OrbWorks Community Forum • View topic - Mathematical Factorials

Mathematical Factorials

Discuss PocketC for Palm OS (including Desktop Edition)

Postby slmiller on Thu Apr 19, 2001 7:36 pm

I am writing a program that will do statistical analysis for einsteinian solids (In english, I'm writing a program to suck up to my physics teacher :-) I have a problem though. The formula I need to impliment uses a factorial. I need to know if there is a built in function (I have looked, but not found one), or possibly an easy way to do a factorial operation.

The formula I need to implment is:
(3n+u-1)!
---------
u!(3n-1)!

Any suggestions would be very helpful. Thanks.

Duct tape is The Force. It has a light side, a dark side, and it holds the world together.
"To beer. The cause of, and solution to, all of life's problems" - Homer Simpson
slmiller
 
Posts: 63
Joined: Mon Jan 08, 2001 6:09 pm
Location: USA

Postby wolfgang on Thu Apr 19, 2001 10:50 pm

Hello,

No, there is no built-in function for that. You find an implementation of the factorial (PocketC source code) on my home page:

http://pages.prodigy.net/gwen.and.wolfgang/

Go to the ABC section (PocketC tutorial), it's one of the examples, in chapter 7 (exercise 7.1). It also deals with the fact that PocketC's numerical range (float, and even more for int) is quite limited which is a serious problem with this type of functions.

If you need a larger numerical range, on my home page you also find a PocketC source code library to deal with integers and floats of arbitrary numbers of digits. It will be slower than the built-in operations, but it will work no matter how large your numbers get.

Wolfgang




Edited by - wolfgang on 04/19/2001 17:52:46

Edited by - wolfgang on 04/19/2001 17:53:33
Composing music on the PocketPC! - http://www.pdamusician.com
wolfgang
 
Posts: 281
Joined: Tue Dec 12, 2000 4:22 am
Location: USA

Postby wolfgang on Fri Apr 20, 2001 12:46 am

Hello again,

I liked this little exercise and sat down to code it. Using my arbitrary precision library (actually only the integer part is needed), the solution is almost trivial (note that the large integers are stored as STRINGS, not as int's. An additonal remark, I wrote the library for the WindowsCE version of PocketC (no 4K limit on the source code), so it will not fit into a single Palm memo. The desktop compiler should take it as it is, otherwise you have to split it up. In the code below, I had to replace the plus sign (gets eaten by the webboard) with the word PLUS.

Wolfgang

[code]

#include "apmlib.pc"

string factorial (int n)
{
string nfac;
int i;

nfac = "1";

for (i = 2; i <= n; iPLUSPLUS)
{
nfac = imult (nfac, i);
}

return (nfac);
}

main ()
{
string result;
int n, u; // could be defined as string, but PocketC does automatic type cast

n = gets ("n = ?");
u = gets ("u = ?");

result = idiv (factorial(3*nPLUSu-1), imult (factorial(u), factorial (3*n-1)));

alert ("result = " + result);
}
Composing music on the PocketPC! - http://www.pdamusician.com
wolfgang
 
Posts: 281
Joined: Tue Dec 12, 2000 4:22 am
Location: USA

Postby slmiller on Fri Apr 20, 2001 1:12 am

Thanks. I figured I'd have to code it myself. I was hoping that there was some built in function that I just hadn't seen. Thanks for all your help.

Duct tape is The Force. It has a light side, a dark side, and it holds the world together.
"To beer. The cause of, and solution to, all of life's problems" - Homer Simpson
slmiller
 
Posts: 63
Joined: Mon Jan 08, 2001 6:09 pm
Location: USA


Return to PocketC for Palm OS

Who is online

Users browsing this forum: No registered users and 1 guest

cron