Re: Number of decimals

"floobydoo2000" <[email protected]>
Newsgroups gmane.comp.windows.gui4cli
Message-ID <[email protected]>
Thanks Fred,

I've tried it out and it works as expected, with a couple of (also expected) new app glitches.  Only the +,-,/, and* functions work.  This is enough for the code that Frans showed he was having trouble with.

I looked at the eval.c program and saw that functions like sin, cos, tan, ^, and ln were used, but could not figure out where they were defined.  I haven't got a copy of the G4C_API.h file.  Are there prototypes for these functions there?

Thanks
Mike

--- In [email protected], "fredfjord@..." <fredfjord@...> wrote:
>
> Hi Frans, Mike,
> 
> I placed Eval.zip in the Temp folder.
> I made it just to learn so it is not fully tested so i placed it in the Temp folder.
> Perhaps you want to try it, this is how it can be used:
> eval.dbl A5 ($A5*$A8/$B2)
> B3=$A5
> eval.setformat ".10f"
> eval.str F (1-$C4+$B3)
> say "Answer is $F"
> 
> The eval.dbl stores the result as a string in a hex format, not usable for people but no loss off precision for further calculations.
> 
> Regards,
> Fred.
> 
> 
> --- In [email protected], "fredfjord@" <fredfjord@> wrote:
> >
> > Hi Frans,
> > 
> > I suppose the result will be a string of: (1/10000000)
> > Only the $var will be translated, the ( and ) has no special meaning unless there is a $ in front of it.
> > The dll i made can put the result as a string #hex presentation of a double so it can be used in the next calculation(s) without loss of precission.
> > 
> > Fred.
> > 
> > 
> > --- In [email protected], "Marianne" <marianne976@> wrote:
> > >
> > > 
> > > 
> > > 
> > > Hi Fred
> > > 
> > > Thanks.
> > > 
> > > I did that but the problem is when A = 1 and B = 10000000 then what about $a/$B? If one uses now $($A/$B) then Gui4Cli rounds off to 6. While I am writing this I am thinking of ($A/$B) without $ infront but if I am correct Gui4Cli will see this as 3 different "statements" and not one.
> > > 
> > > Regards.
> > > 
> > > Frans
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > --- In [email protected], "fredfjord@" <fredfjord@> wrote:
> > > >
> > > > Hi Frans,
> > > > 
> > > > //Is there a 'trick' to convert a caclulation immediately to a string?
> > > > //Cannot use E = $(5/10000000)
> > > > 
> > > > Easy, just use E = (5/10000000)
> > > > Since you use it later in a calculation then at that time it will be calculated and not now and rounded.
> > > > 
> > > > Fred.
> > > > 
> > > > 
> > > > --- In [email protected], "Marianne" <marianne976@> wrote:
> > > > >
> > > > > Hi Mike and Fred
> > > > > 
> > > > > Me again and thanks for all the info and also on the ttmath and bc programs.
> > > > > 
> > > > > Mike in your posting you said the following and I quote:
> > > > > 
> > > > > "I'd like to see exactly how you got this because it is very curious."
> > > > > 
> > > > > Here is a small part of the original program, the problem part. The other values is from calculations from the program. I hope it will help (The comments were just for me while I was struggling):
> > > > > 
> > > > > Run the program with E = 0.0000005, your answer will be app 0.25, this is what it must be.
> > > > > 
> > > > > Change E to 0.000001 and run again. The answer is now 0.15003
> > > > > 
> > > > > Gcwin open
> > > > > A8 = 362880
> > > > > A5 = 0.066167
> > > > > M2 = 19
> > > > > C4 = 0.95206
> > > > > //E must be a string else it is rounded to 6 - this is my problem.
> > > > > //Is there a 'trick' to convert a caclulation immediately to a string?
> > > > > E = "0.0000005" //Cannot use E = $(5/10000000) or E = 0.0000005, becomes 0.000001
> > > > > //
> > > > > Z=$(6+($M2-2)/2)
> > > > > P5=$((PI*2/$Z)^(1/2)*($Z)^($Z))
> > > > > P5 = $($P5 * $e)
> > > > > Z=$($Z-5)
> > > > > zz = $($Z*($Z+1)*($Z+2)*($Z+3)*($Z+4))
> > > > > B2=$($P5/$zz) 
> > > > > A5=$($A5*$A8/$B2); B3=$A5
> > > > > F=$(1-$C4+$B3)
> > > > > say "Answer is $F"
> > > > > 
> > > > > This is what I am talking about. (The large values are the problem, will always be the case. In the final answer I am only interested in the first 4 decimals.)
> > > > > 
> > > > > Hope it is clear.
> > > > > 
> > > > > Fred I  will look again at the dll. As said I already wrote one and is busy testing it.
> > > > > 
> > > > > Once again thanks for everything.
> > > > > 
> > > > > Kind regards.
> > > > > 
> > > > > Frans
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > --- In [email protected], "fredfjord@" <fredfjord@> wrote:
> > > > > >
> > > > > > Hi,
> > > > > > 
> > > > > > The evaluation in G4C uses the double data type and gives about 15 digits precision.
> > > > > > A calculation should be accurate only the result is rounded because it is converted into a string with standard 6 digit precision.
> > > > > > 
> > > > > > When you do a calculation, store it in a var (then rounded) and uses the var it in a next calculation the result could be a little less accurate then when in one calculation.
> > > > > > 
> > > > > > My intention was to use bigger precision or other notation as string result.
> > > > > > Also using a double result in a hex string format for later calculation would be possible.
> > > > > > Like a said a set float command would be better but i suppose Dimitris is busy (well, we all are :)).
> > > > > > 
> > > > > > @Frans:
> > > > > > I just looked at FreeBASIC and it looks good but i have not made a dll with it yet.
> > > > > > Perhaps i can make your functions in the eval module or i could make your dll into a G4C dll.
> > > > > > In the Sql3 source you can see what you need for a G4C dll, the TRex module is even smaller, only a few functions.
> > > > > > 
> > > > > > I agree to use what is available in G4C but Dimitris has it made easy to use a dll in G4C.
> > > > > > And Windows is a big collection of dll's :)
> > > > > > 
> > > > > > And we all like Gui4Cli else we would not be on this list :)
> > > > > > 
> > > > > > Regards,
> > > > > > Fred.
> > > > > > 
> > > > > > 
> > > > > > --- In [email protected], "floobydoo2000" <michael.bernas@> wrote:
> > > > > > >
> > > > > > > I would agree that an answer of .15 when .24 is expected is inaccurate.  With 6 signifcant digit math you should get 4 or 5 digit accuracy.  Here, you didn't even get one.  I'd like to see exactly how you got this because it is very curious.
> > > > > > > 
> > > > > > > I'd also like to show that G4C holds small numbers like 0.000000005 accurately even if they get printed out as zero.  the following code shows this:
> > > > > > > 
> > > > > > > say $(0.000000005)
> > > > > > > say $(0.000000005/0.0000000025)
> > > > > > > 
> > > > > > > results in:
> > > > > > > 
> > > > > > > 0
> > > > > > > 2
> > > > > > > 
> > > > > > > I do not view showing such a small number as zero to be a bug, but it would be a welcome feature to have such small numbers printed in scientific notation instead.
> > > > > > > 
> > > > > > > I'd like to point out that using the math module that GUI4Cli in a math dll will not improve things as Fred suggests below.  This module is really only good for 6 sigificant digits.  I would recommend trying ttmath (google it, it's on sourceforge now, the original site www.ttmath.org seems to be gone) for anyone wanting to try it.  The author demonstrated this module by writing a calculator called ttcalc.  ttmath is, like bc, arbitrary precision.
> > > > > > > 
> > > > > > > Thanks,
> > > > > > > Mike
> > > > > > > 
> > > > > > > 
> > > > > > > --- In [email protected], "Marianne" <marianne976@> wrote:
> > > > > > > >
> > > > > > > > 
> > > > > > > > 
> > > > > > > > 
> > > > > > > > 
> > > > > > > > 
> > > > > > > > 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/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.