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 - Double Precision

Double Precision

Discuss PocketC for Palm OS (including Desktop Edition)

Postby winthrom on Sat Mar 13, 2004 4:36 pm

Does MathLib support Double Precision?
If so, how can I access that for a program I wrote? This program calculates Fibonacci numbers the standard way and then uses a formula to calculate the same number. The difference is that the formula lets you calculate a specific number in the series without calculating all the preceeding oned the way the standard version does. Problem is :?:that after som number of successful computations with small Fibonacci numbers, it starts to fail. Double ptrcision would let me use it to solve most useful problems on the PalmPilot.

The output fails at sequence number 24, see below.
--------------------------------
// FIBONACCI.c
/*#define fib_index=((int)(z=(log(FIB[j])+log(5)/2)/log (golden)+0.00));*/

main()
{
int FIB[256];
int i,j,k,kk,x;
float z, golden,zz;
clear();
golden=1.6180340;//39; these last digits are not used by PocketC
zz=1-0.065646318;
puts(zz+"\n");
k=317811;j=28;
z=(pow(golden,j)-pow((1-golden),j))/sqrt(5.0);
i=z+0.9; // this rounds up for the integer comparison (shouldnt need)
puts(z +"--"+i+"--"+k+"\n");

for(i=0;i<=255;i++)FIB[i]=0;
i=0;
FIB[i]=0;
FIB[i++]=1;

for(j=2; j<=255; j++)
{//begin for j
FIB[j]=FIB[j-1] + FIB[j-2];//Standard formula

k=(int)(((log10(FIB[j])+0.349485002)/0.20858764)+0.04);//new formula

puts("\n#"+(j-1)+"-F"+FIB[j]+"-#"+k+"+x=");

for
(x=FIB[j-1]+1;x<=FIB[j];x++)
{//begin for x

kk=(int)(((log10(x*zz)+0.349485002)/0.20858764)+0.04);

if(kk== k)
{puts(x+"dif="+(FIB[j]-x));break;}

//f(x==FIB[j-1])
//{puts(x+"=F[j-1]"+FIB[j-1]);}
}//end for x
//if(x-1==FIB[j])
{puts(" "+(x-1)+"="+FIB[j]);}

if(FIB[j]>=100000000)break;
}//end for
}
------------------------------
Output:
------------------------------
FIB SEQUENCE 1-27

#1-F-1-#-1+x=1dif=0
#2-F-1-#-1+x=
#3-F-2-#-3+x=2dif=0
#4-F-3-#-4+x=3==3
#5-F-5-#-5+x=5==5
#6-F-8-#-6+x=8==8
#7-F-13-#-7+x=13==13
#8-F-21-#-8+x=21==21
#9-F-34-#-9+x=34==34
#10-F-55-#-10+x=55==55
#11-F-89-#-11+x=89==89
#12-F-144-#-12+x=144==144
#13-F-233-#-13+x=233==233
#14-F-377-#-14+x=377==377
#15-F-610-#-15+x=610==610
#16-F-987-#-16+x=987==987
#17-F-1597-#-17+x=1597==1597
#18-F-2584-#-18+x=2584==2584
#19-F-4181-#-19+x=4181==4181
#20-F-6765-#-20+x=6765==6765
#21-F-10946-#-21+x=10946==10946
#22-F-17711-#-22+x=17711==17711
#23-F-28657-#-23+x=28657==28657
#24-F-46368-#-24+x=46341dif=27
#25-F-75025-#-25+x=74912dif=113
#26-F-121393-#-26+x=121099dif=294
#27-F-196418-#-27+x=195762dif=656
#28-F-317811-#-28+x=
winthrom
 
Posts: 5
Joined: Sat Jul 20, 2002 8:50 pm
Location: USA

Postby dewey on Thu Mar 18, 2004 2:35 am

MathLib does support doubles, however PocketC currently does not.

Jeremy
dewey
Site Admin
 
Posts: 749
Joined: Sun Oct 21, 2007 5:12 am

Postby winthrom on Sun Mar 21, 2004 4:30 pm

Jeremy:
Do you plan to support double precision, or make access to the MathLib functions available?;)
Michael F. Winthrop
winthrom
 
Posts: 5
Joined: Sat Jul 20, 2002 8:50 pm
Location: USA

Postby wolfgang on Sun Mar 21, 2004 6:14 pm

Hi,

I have written some PocketC code that can handle integer and floating point numbers with arbitrary precision. It's not lightning fast, but it works; currently supported are only the basic operations (+, -, *, /, comparison), but you could use Taylor series to implement higher functions like sin() or log() based on those base operations.

If you are interested, drop me a note (wolfgang@pdamusician.com) and I can send you the source.

Wolfgang


Composing music on the PocketPC! - http://www.pdamusician.com
Composing music on the PocketPC! - http://www.pdamusician.com
wolfgang
 
Posts: 281
Joined: Tue Dec 12, 2000 4:22 am
Location: USA

Postby winthrom on Sat Mar 27, 2004 5:19 pm

Wolfgang:
I would use the arbitrary precision functions however I cannot use it for Logorithms, trig functions, etc. In my sample code you see a log(BASE 10)in the `"formula". Calculating the log to sufficient precision is not practical. I wrote a program for navigation (see contributions) that uses trig functions heavily. I have not tried to make it available for use in real navigation because the calculations are to rough. It needs double precision also. I made the request about MathLib because I thought that there might be a way to access the "double" functions. Jeremy may well be holding off on "double" because that is a significant upgrade entailing lots of work and testing. However, I have noted that a few university types put PocketC aside because of the precision issue, so usability (in practical situations) seems to come down on the side of adding it.

Michael F. Winthrop
winthrom
 
Posts: 5
Joined: Sat Jul 20, 2002 8:50 pm
Location: USA


Return to PocketC for Palm OS

Who is online

Users browsing this forum: No registered users and 2 guests

cron