Posts: 2,020
Threads: 24
Joined: Jun 2002
scm, you are a genious. I salute you!
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Posts: 309
Threads: 15
Joined: Jul 2003
I just know where my old text books are.
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)
For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Posts: 90
Threads: 8
Joined: Aug 2003
First, when i say you must have math skills, i mean it's for understand that formula.
Second, if i've to program large numbers arithmetic i don't use strings, i use dinamic arrays of integers.
Third, i speak spanish and i learn english watching tv, so sometimes i write things that i won't to say. Excuseme please.
Posts: 3,343
Threads: 83
Joined: Mar 2003
Quote:Oracle what you need is some numerical background.
I have some, that's why I'm making StatLib. All I needed was the series, and you have told me it, cheers.
Also, can you store 3000! in a dynamic integer array? Or SIN(.432876)?
Quote:Note2: There's a library called bigint, you start taking a look on it.
Hehe, that was the basis of StatLib. Neo (who is now back from holiday!) made it and I've taken it and added negative and decimal number support. Now for the actual stats functions...
EDIT: could someone show me a function that uses SCM/xhantt series to calculate x^y? I suck, I've tried. Just if someone can do that I can convert it to work with strings easily.
Posts: 6,419
Threads: 74
Joined: Mar 2002
Posts: 3,368
Threads: 195
Joined: Jan 2003
really really GHEY!!!!!!:
Quote:One of the "missing links" in VB.Net is the absence of the unsigned integer type.
That's so absolutely stupid! One thing that should make us all see even more clearly now is that programming languages today aren't necessarily "better" than those that came before them...
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest.
Posts: 3,343
Threads: 83
Joined: Mar 2003
Quote:really really GHEY!!!!!!:
Quote:One of the "missing links" in VB.Net is the absence of the unsigned integer type.
That's so absolutely stupid! One thing that should make us all see even more clearly now is that programming languages today aren't necessarily "better" than those that came before them...
How is this relevant?
SCM: thanks for your email. If it works and I can convert it to strings then you've saved me a lot of hassle, cheers.
Posts: 309
Threads: 15
Joined: Jul 2003
If anyone else is interested, this is my code Code: DECLARE FUNCTION eM# (BYVAL x#)
DECLARE FUNCTION eT# (BYVAL x#)
DECLARE FUNCTION lnT# (BYVAL x#)
DECLARE FUNCTION AToTheX# (BYVAL a#, BYVAL x#)
INPUT "Enter a,x: ", a, x
PRINT a; " ^"; x; "="; AToTheX(a, x)
DEFDBL A-Z
FUNCTION AToTheX (BYVAL a, BYVAL x)
AToTheX = eT(x * lnT(a))
END FUNCTION
FUNCTION eM (BYVAL x)
' MacLaurin Series for e^x
' Not used
' Is slow to converge for all but small numbers.
' Very slow for large numbers.
' Does not agree with EXP(X) for x<-4. For example
' eM (-9.9) only returns single precision accuracy
' (assuming EXP is correct)
n = 0 '\ n = 0
e2 = 1 '/ term
DO
e1 = e2 ' Previous value for series
n = n + 1 '\
Term = 1 ' | nth term
FOR j = 1 TO n ' |
Term = Term * x / j ' | x^n / n!
NEXT '/
e2 = e2 + Term ' New value for series
LOOP WHILE ABS(Term) > e2 / 1D+16 ' Convergence check
' PRINT "n ="; n; ' test code (delete)
eM = e2 ' Function assignment
END FUNCTION
FUNCTION eT (BYVAL x)
' Taylor Series for e^x
' This converges faster than the MacLauren series,
' but has a large overhead to overcome. For large
' numbers it is definitely faster.
' It agrees well with EXP(x) (The last digit is sometimes off)
C = INT(x) + (x = 1) ' c=0 when x=1. This reduces the Taylor
' Series to the MacLauren series when
' x=1. You could gain some performance
' by extending this to small values of
' x. For example
' IF ABS(x - 1) < 4 THEN c = 0
dx = x - C
e0 = 1 '\
IF x > 1 THEN ' | Determine a value close to
e1 = eT(1#) ' | the desired value using an
FOR j = 1 TO C ' | integer exponent
e0 = e0 * e1 ' | (note e1 is used here for e^1,
NEXT ' | but is used differently below).
ELSEIF x < 0 THEN ' |
e1 = eT(1#) ' |
FOR j = 1 TO -C ' |
e0 = e0 / e1 ' |
NEXT ' |
END IF '/
n = 0 '\ first term
e2 = e0 '/ e^c
DO
e1 = e2 ' previous value
n = n + 1
Term = e0 '\
FOR j = 1 TO n ' | nth term
Term = Term * dx ' | e^c * (x - c)^n / n!
NEXT '/
e2 = e2 + Term ' New value of series
LOOP WHILE ABS(Term) > e2 / 1D+16 ' convergence check
' PRINT "n ="; n; ' for test purposes only (delete)
eT = e2 ' Function assignment
END FUNCTION
FUNCTION lnT (BYVAL x)
' Taylor series for ln x
' (only valid for x > 0)
' estimate ln
x$ = STR$(x) '\
DE = INSTR(x$, "D") + INSTR(x$, "E") ' |
IF DE > 0 THEN ' |
Pwr10 = VAL(RIGHT$(x$, 2)) ' |
Mantissa = VAL(LEFT$(x$, DE)) ' | Convert to scientific
ELSE ' | notation so that I can
Pwr10 = INSTR(x$, ".") - 3 ' | use LOG to estimate the
IF Pwr10 = -1 THEN ' | the ln. If you round
ChrPos = 3 ' | the mantissa off to
WHILE MID$(x$, ChrPos, 1) = "0" ' | double precision you
CurPos = ChrPos + 1 ' | will be able to use
WEND ' | LOG to estimate
Pwr10 = 2 - ChrPos ' |
END IF ' |
Mantissa = x / 10 ^ Pwr10 ' |
END IF '/
Mantissa = INT(1000 * Mantissa + .5) / 1000 ' rounding to approximate
' what you will be doing
n = 0
ln2 = LOG(Mantissa) + Pwr10 * LOG(10) ' n=0 term (Estimated Ln)
C = eT(ln2) ' Use ln2 to determine C
dx = x - C
DO
ln1 = ln2 ' Previous value for series
n = n + 1
Term = -1 / n '\
FOR j = 1 TO n ' | nth term
Term = -Term * dx / C ' | (-1)^n*(x - c)^n/(-n*c^n)
NEXT '/
ln2 = ln2 + Term ' New value for series
LOOP WHILE ABS(Term) > ABS(ln2 / 1D+17) ' Convergence test
' PRINT n ' test code (delete)
lnT = ln2 ' Function assignment
END FUNCTION
It's fairly simple, but as usual took me way too long (I specialize in typos). I can't understand how so many of you were able to write decent games in an hour.
Oracle,
I have made a minor change in the convergence test (LOOP) lines. You may have noticed that I was calculating a value I already knew.
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)
For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Posts: 3,343
Threads: 83
Joined: Mar 2003
Cool. I'll be fiddiling with it soon. I can make it more accurate when I replace 1D17 with 1D32000 :lol:
Posts: 3,368
Threads: 195
Joined: Jan 2003
obviously you haven't clicked on na_th_an's link...
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest.
|