Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com Speed Question

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 10-27-2002, 04:27 AM PM User | #1 Shawn Curry New Coder   Join Date: Oct 2002 Location: middle of nowhere Posts: 34 Thanks: 0 Thanked 0 Times in 0 Posts Speed Question I'm still working on that numbers class. I'm dam proud of that thing!! It can do irrational division now (like 1 div by 7). I'm working on a pattern matching function for it now so it can identify when its a repeating number, and I know how im gonna do it too(pretty cool for my first big prog). Anyway it got me thinking.. The heart of the program is it's conversions. It takes a character and subtracts 48 to turn it into an integer, and adds 48 to an integer to convert it to a char. This and the constructors probably get the most calls of the whole program(this probably gets more). The integer conversion looks just like the character conversion, and that will have to remain how it is, but im wondering if I can make the character conversion faster. Right now, its this: char convert(int in) { char output = (in + 48); return output; } I'm thinkin about doing this: char convert(int in) { char* num = "0123456789"; return num[in]; } This way it never even has to add. Which do you think would be faster?
 10-27-2002, 09:28 PM PM User | #2 bcarl314 Mega-ultimate member   Join Date: Jun 2002 Location: Winona, MN - The land of 10,000 lakes Posts: 1,855 Thanks: 1 Thanked 45 Times in 42 Posts Not to be a stickler or anything but... 1 divided by 7 is not irrational division, 1 divided by the sqaure root of 7 is, the other is strictly division. Just thought I'd be a pain in the butt about it. Also, what language are you using? Java? Why not use parseInt to convert a char to an int???
 10-28-2002, 03:01 AM PM User | #3 Shawn Curry New Coder   Join Date: Oct 2002 Location: middle of nowhere Posts: 34 Thanks: 0 Thanked 0 Times in 0 Posts Im using MSVC++ Intro Ed 6. I think Java has a BigInteger and BigDecimal class, so i've heard. I'm really just doing it b/c its a really good learning tool for me. I'm in school for it now but I've been teaching myself for about 4 months now and this is really my first original idea I've taken from design to execution. BTW 1/7 (one seventh) = 0.142857142857142857142857...infinity in other words its an irrational number but we can represent it as: ________ 0.142857 which is what it does now. It stops at 200 digits if its an irrational number, it feeds it into my pattern matcher and it extracts the pattern that starts the earliest in the number In other words: 0.784356312345123451234512345 it knows to take 12345 instead of 23451 or 34512. Pretty cool huh?
 10-28-2002, 12:29 PM PM User | #4 bcarl314 Mega-ultimate member   Join Date: Jun 2002 Location: Winona, MN - The land of 10,000 lakes Posts: 1,855 Thanks: 1 Thanked 45 Times in 42 Posts Sorry, again I must insist that 1/7 is not an irrational number. By mathematical definition an irrational number is any number (n)that cannot be represented in the following form. where a, b are integers and b !=0 , n = a/b. Thus in your example 1/7: a= 1, b =7. The number is not irrational. However, the number: square root of 2, cannot be represented in the form a/b where a & b are intergers and b!=0. So the square root of 2 is irrational. Then we have trancendental numbers which include the likes of pi! But that's a whole new ball of wax. To sum, 1/7 is not an irrational number.
 10-28-2002, 02:33 PM PM User | #5 Shawn Curry New Coder   Join Date: Oct 2002 Location: middle of nowhere Posts: 34 Thanks: 0 Thanked 0 Times in 0 Posts Ok ok. I guess i'm using the elementary definition of irrational. What was trying to say is that it is a number which has no definate stopping point, it just goes on and on forever. But, I can approximate IRRATIONAL numbers to a given precision. My algorithm extracts 1000 digits / sec (I timed it) on a P4 1.8. There is also very little speed difference when the divisor < 100 digits. The speed is unaffected by the dividend length.
 10-28-2002, 04:15 PM PM User | #6 bcarl314 Mega-ultimate member   Join Date: Jun 2002 Location: Winona, MN - The land of 10,000 lakes Posts: 1,855 Thanks: 1 Thanked 45 Times in 42 Posts That's pretty cool. I once created a program that would find Mersenne primes, only ran into problems once numbers couln't be represented in 32 bits. :P But I noticed on a P1 66Mhz, it took about 6 minutes to find the first 9, on a P4 1.7 about 1 sec. What a difference!
 10-29-2002, 07:11 AM PM User | #7 Shawn Curry New Coder   Join Date: Oct 2002 Location: middle of nowhere Posts: 34 Thanks: 0 Thanked 0 Times in 0 Posts The reason I started to build this was for large prime numbers. I used my base class (Whole numbers) to build the Sieve of Erosthanes(an elementary method of computing primes). I had this independant research assignment about computer encryption codes and it said that it was nearly impossible to compute 200 digit primes, so I just had to try. Turns out it is pretty difficult. The first prototype was able to extract all the primes under 1,000 in the blink of an eye, but the higher you go the slower it goes. Took about 10 mins to compute all under 10,000. The next one was smarter(it used a queue so it was only checking exactly as many primes as it needed to) but it still took about 7 mins to get up to 10,000. I had some ideas about how to get up to 200, namely to start at a 200 digit number and use the queue more like a stack(clear it out as goes along to save memory) but I think it still would have taken days just to confirm one 200 digit prime. It would probably eliminate a whole bunch in a hurry, but it would have do divide by billions of different numbers when it ran into a prime. Anyhow, I've been working all day on getting this decimal straight on my division algorithm. It gets all the numbers right, and it gets the decimal point right about 75% of the time. It seems so simple, but I'm on my fourth complete rewrite of the algorithm, and I cant even count how many times i've rewritten the decimal point logic. Ideas??
 10-29-2002, 12:34 PM PM User | #8 jkd Senior Coder     Join Date: May 2002 Location: metro DC Posts: 3,163 Thanks: 1 Thanked 18 Times in 18 Posts We are doing this in our APCS class. We also have previously written a Rational number class. Which means, on top of BigInt, we will be able to do: BigInt/BigInt to represent basically any Rational number you could possibly work with. Just a speed note: Adding and subtracting 48 is going to be slow after a while. Create an enumerable type and go through that instead. Looking up what is at a memory address is faster than addition/subtraction. __________________ jasonkarldavis.com
 10-30-2002, 01:39 AM PM User | #9 Shawn Curry New Coder   Join Date: Oct 2002 Location: middle of nowhere Posts: 34 Thanks: 0 Thanked 0 Times in 0 Posts Yeah I thought about that too. I may put that char array at global scope so it only initializes it once. All my algorithms are still pretty darn quick, though. My division algorithm extracted 3000 digits in 0.83 seconds this morning. It can get 500 just as fast as I can hit enter to debug it, and that's dividing 2 decimal numbers. And I'm in my first quarter in school. We dont even have an APCS program, and I'm not going to be in any programming classes until my third quarter. So I can't even ask for help when I need it. Ah well, I'm going to end up writing 4 different division algorithms for that decimal place and only use the operator as a logic shell. I can't figure out a good way to generalize the logic for the decimal placement. I can get it to work for each different case, but when i change something other cases stop working. #p It'll be really cool when its done though !

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 05:25 AM.