GNOME Bugzilla – Bug 563217
Add prime number functions
Last modified: 2009-09-28 23:07:38 UTC
It would be nice if gcalctool would offer a way to factorize a number into its prime factors (this would also allow to detect a number as prime). Though this is apparently very difficult for large numbers, I think it would be sufficient to limit this function to input values which can be factorized in reasonable time (I think numbers up to 1.000.000 should be doable and this should also suffice as upper limit). I am not aware of any simple way to get this functionality on a Linux+Gnome desktop at the moment. All the more reason to make it available in the ubiquitous desktop calculator :-)
That's a really cool idea! Thanks.
Created attachment 144112 [details] [review] Add factorization function (Bug #563217)
Some day, I'm gonna learn how to properly use git bz attach… This adds a fact button to the scientific mode, which factorizes the number, and prints the prime factors as a series of multiplications. While it will be slow at finding primes bigger than a million, it's reasonably quick if the number is not prime. This patch does not include documentation updates - I'll add those later, if you think the user interface is sane.
Created attachment 144122 [details] [review] Add factorization function (Bug #563217) This updated patch handles 1's correctly, and is much, much faster due to me no longer unnecessarily resetting the divisor all the time.
I just committed new UI changes so I've updated the patch and committed: http://git.gnome.org/cgit/gcalctool/commit/?id=a6ba6319f99b901ac7c493f2302128d63020dde3 I also updated to make it handle factorizing 1 and negative numbers. Thanks Robin!
One request, could you move the factorization code into mp.c. This will help when we make gcalctool threaded so factorizing a large number will not lock up the UI (bug #576371). p.s. The master is now 2.29 so feel free to commit changes directly and worry about getting them perfect later.
Done. However, it creates a bit of unpleasant code, since I need a list of MPNumbers, not just one. Please complain.
No complaints. Works well and we can look at deciding on a vector format later if we have more functions that use vectors.