MegaPow(), i need superman mathematical

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

I have tested your great code Michael 8)

But i believe your function can't use the float :roll:

Because :

Code: Select all

Debug Pow(2,3)
Debug Round(Pow(8, 1/3), 1)
Result :

Code: Select all

8.0
2.0
And with your code :

Code: Select all

PutNumber(@"2",x) 
VNFPow(x,3,z) 
Debug Number(z)

PutNumber(@"8",x) 
VNFPow(x,1/3,z) 
Debug Number(z) 
Result:

Code: Select all

8
1
:shock:
ImageThe happiness is a road...
Not a destination
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

Michael Vogel wrote:
pdwyer wrote:Apparently you can use Fast Fourier transforms to do this lots quicker.

Except I don't understand Fast Fourier transforms :P

That said, even if you do it quicker, where to you get the space?
Hi pdwyer, give me a hint, please...
...what is done quicker?
I'm not going to pretend to understand it but take a look here
http://en.wikipedia.org/wiki/Multiplica ... #Toom-Cook

@Kwaï chang caïne That would work but like I said, my code only supports integers at the moment so 1/5 (1 divided by 5) is a number my code can't currently display. Quite a few people worked at the same time on these, we all ended up with our own but we discussed methods a lot. perhaps you'd like to look through these and add ideas for floating point operations. I have only used middle school math level in mine (as I only ever went to school till about then ;) ) so you should understand it. Please contribute! :)
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

That would work but like I said, my code only supports integers at the moment so 1/5
Excuse me, but I did not understand all you said, because of my poor translation :oops:
I understand quickly, but you must explain me a long time :lol:
so you should understand it. Please contribute!
Let me help you so much, but with my bad level mathematical, my null level of English, and my programming level not higher. :oops:
Here you are with a partner, who really did not have much value :wink:
ImageThe happiness is a road...
Not a destination
User avatar
Michael Vogel
Addict
Addict
Posts: 2806
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Kwaï chang caïne wrote:I have tested your great code Michael 8)

But i believe your function can't use the float :roll:

Code: Select all

VNFPow(x,1/3,z) :shock:[/quote]

You're right, I just do integer math...

One one hand you can "simulate" floating points by by multiplying your numbers by 10^n on the other hand the function CNFPow only supports an (positive long) integer values for the power parameter.

So my power function is limited, but depending of your aims it could be a help for you...

Michael


Some remarks:

 • VNFPow(x,1/3,z) is interpreted like VNFPow(x,0,z) because the parameter b in VNFPow(...,b,...) is an integer type

 • maybe you can use the function for iterations, if you are searching 627213431734272 ^ (1/3) for example you can check, if the result of a^3 is higher or lower than 627213431734272 and change a until you find the solution
Last edited by Michael Vogel on Tue Feb 12, 2008 1:45 pm, edited 1 time in total.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

maybe you can write a div() function for us that outputs a string float! "3.141592654" :)

You need junior school math + basic string programming. Once you get something really basic then post it and others will help optimise it or give ideas. Thats how we wrote the last functions. We tend to stop when we have whatever solves our problem at that time. I didn't try div or mod for months after the others. If I need negative I will add those too later.

You need floats so please help by making a start :)
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

You need floats so please help by making a start
I will tried, with no garanty :oops:

Thanks for your help that move me a lot 8)
ImageThe happiness is a road...
Not a destination
User avatar
Michael Vogel
Addict
Addict
Posts: 2806
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Floats must not be used for most of the commonly used math functions (add, mul, div,...) if you remember the number of ciphers after the floating point:

3.45 x 6.78 = 23.391

can be done with integer functions...

...because 345 x 678 = 233910
...and 2+2 decimal playes makes 4 places:

voilá: 23 . 3910
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

interesting.

What happens with 1/3 ? ( can see for non recurring ones how this would work but for 0.3333333333333333. etc ?
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
User avatar
Michael Vogel
Addict
Addict
Posts: 2806
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

pdwyer wrote:interesting.

What happens with 1/3 ? ( can see for non recurring ones how this would work but for 0.3333333333333333. etc ?
You are right, of course (again one more reason, why I still haven't done a div routine until now :wink:)

But doing calculation with floats is also a kind of allowing to be a liitle bit generous 8)
Numbers like 0.1 and 0.2 are also rounded in their binary representation, so 1/3 would also be a situation to cut the precision after a specific number of digits.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

You've given me some ideas (again :) ) I might have a play with this tonight.

For testing:

fdiv1()
that can only accept string floats as input and INTs them to div() them, drop the remainder and give the dec places it's got from there (so 1/3 will just come out as 0.3 etc) and do what is in your example above

fdiv2()
that can accept ints but gets the remainder from the mod and generates to x decimal places in a loop.

From there try to merge them into fdiv() which can accept floats and generate the extra decimal places.

Considering it's going to be using my integer div and mod functions it's going to be kind of slow.

See if I can beat you to generating pi to 1000 decimal places ;) (a long way off yet)

(this won't really be the answer to sqr() though. )
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Post Reply