Re: Number of decimals
"Marianne" <[email protected]>
| Newsgroups | gmane.comp.windows.gui4cli |
|---|---|
| Message-ID | <[email protected]> |
Fred and Daz Once again thanks for all the information. This might sound strange but I am not that concerned about precision. I am more interested about the number of decimals shown. I wrote a program in Gui4Cli to calculate the probabilities for the F-probability distribution, say for an F-value of 1.49 with Df1 = 3 and Df2 = 19. The answer should be 0.25 At one stage I perform a calculation with a variable with 7 decimals, something like 0.0000005.... This value is given as 0.000001 by G4Cli (rounded to 6 decimals. My final answer is 0.15??? using Gc4 instead of 0.24???? What I did then was to define the variable say A directly in Gui4cli as A = 0.0000005 and repeat the calculation and I got the correct answer.(I just want to point out that I know that is not a problem of Gui4Cli.) Fred, last night I wrote a dll using FreeBasic, testing it and it works fine. Unfortunately it is a system dll and not a "Gui4Cli" dll so one has to use the sysdll command. (I do not have a clue how to write a Gui4Cli dll, although I had a look at the dll tutorial.) This dll will be app. 20 KB and includes the Normal, T-, F- Chi-Square, Gamma and other distributions also with the inverse functions, but I still prefer not to use dlls unless it is not possible to perform all calculations within Gui4Cli (I repeat, I like Gui4Cli.) The majority of the above distributions work in Gui4Cli, except for the rounding in a few cases. Once again I want to thank all of you for the replies. Regards. Frans --- In [email protected], "fredfjord@..." <fredfjord@...> wrote: > > Hi, > > The expression evaluation uses 'sprintf (out, "%f", res))' at the end and the default precision is 6 digits for %f. > I think the best solution would be to add a SET FLOAT witdh.precision statement by Dimitris with default .6 to keep compability. > > Another solution would be to make a math dll, i can try to use the same module G4C uses for math in a dll with a greather precision. > It can take a while since i have a cold and yesterday had 39,3 degrees so i don't think very fast :) > I already did make the eval module as a command line tool so it should not be to difficult. > > Using bc you would have a high precision calculator as long as you use only strings and no calculation in G4C. > > Regards, > Fred. > > > > --- In [email protected], dazroo <daz4roo@> wrote: > > > > Apologies to group for one of those "scattered" replies. > > > > On 18/09/10 00:02, Marianne wrote: > > > > > > > > > > > > > > > Hi Daz and Mike > > > > > > Thanks for the response but BC will not help me. I apologise if my > > > knowledge is not up to date or standard. > > > > > > I am using Gui4Cli currently for all calculations as I can perform all > > > calculations in Gui4Cli. > > > > Floating Point Arithmetic (FPA) is notoriously error-prone in many computer > > implementations. Here's one explanation: > > http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems > > > > > > > Secondly I am a self studied programmer and do > > > not know a lot about programming. I only know a little Basic. Here is an > > > example and if I am off target please let me know. > > > > > > Take the following example: > > > A = 1 > > > B = 1.538 > > > > > > So A/B = 0.649772579597141...... and I want to round this off say to 8 > > > decimals. I cannot do the following: > > > > That result is already inaccurate (before rounding) :( > > > > Copy/Paste the following into the bottom box at: > > http://sciencesoft.at/bc/?lang=en > > -------------------------------------------- > > a = 1 > > b = 1.538 > > g4cans = 0.649772579597141 > > a/b > > a/b - g4cans > > -------------------------------------------- > > and click "Calculate" > > > > Result: > > .65019505851755526657 .00042247892041426657 > > > > That's a g4c inaccuracy of .00042247892041426657 on that one > > calculation. > > > > ( I get the answer of around .65019506 in three other programs. ) > > > > > > > > > > C = $($A/$B) = 0.649773 and send C to the external program, say BC, > > > because Gui4Cli already rounded $C to 6 decimals. I can probably send > > > $A/$B to BC (not tested yet as calculations are sometimes lenghty in > > > statisics and not that easy to do it this way, if possible. (Will not be > > > possible if one uses loops for example.) > > > > > > > I would recommend staying away from the in-built FPA and, instead, > > call an external program (designed for the task) via [DOS.DLL] passing > > FP-like numbers as strings. > > Once your FP calculations are done and rounded, then you can > > present the results in your gui as strings in the precision required. > > > > > In other words it seems to me that all calculations therefore have to be > > > performed with an external program if you want rounding off to more than > > > 6 decimals. Although Gui stands for Graphical User Interface that is not > > > what I want. (The majority of other languages do have a Gui interface, > > > but I like Gui4Cli because of its simplicity. > > > > FP = major complexity :) - no fault of Gui4Cli. > > Use Gui4Cli with a reliably accurate external library routines for FPA. > > > > > > > > Why do I need so many decimals? This is to perform for example > > > convergence problems of Functions, like probabilities and one will be > > > suprised how quick Gui4Cli is.(My standards) > > > > > > If Gui4Cli can give decimals to more than 6 or if a new command such as > > > 'Set Decimals to $value' can be added it will be great but I do not know > > > how easy or difficult it will be. > > > > It would be a daunting task, I think. > > Take your example which I gave to BC: > > What value would more decimal places on the end of an already > > inaccurate result be? ;) > > > > In other scripting language forums, I've seen strong > > recommendations for avoiding doing currency calculations > > in FPA (e.g. 7.55eur). Instead, they suggest do all calculations > > in cents (755c) because you can't get unexpected rounding > > anomalies using integer arithmetic (only programming bugs). > > > > > > > > Regards > > > > > > Frans > > > > > > > To you, also. > > > > daz > > > ------------------------------------ Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/gui4cli/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/gui4cli/join (Yahoo! ID required) <*> To change settings via email: [email protected] [email protected] <*> To unsubscribe from this group, send an email to: [email protected] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/