After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 563217 - Add prime number functions
Add prime number functions
Status: RESOLVED FIXED
Product: gnome-calculator
Classification: Core
Component: general
5.8.x
Other All
: Normal enhancement
: 2.28.0
Assigned To: gcalctool maintainers
gcalctool maintainers
Depends on:
Blocks:
 
 
Reported: 2008-12-04 10:58 UTC by Oliver Gerlich
Modified: 2009-09-28 23:07 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement


Attachments
Add factorization function (Bug #563217) (5.30 KB, patch)
2009-09-27 14:08 UTC, Robin Sonefors (ozamosi)
none Details | Review
Add factorization function (Bug #563217) (4.93 KB, patch)
2009-09-27 17:40 UTC, Robin Sonefors (ozamosi)
none Details | Review

Description Oliver Gerlich 2008-12-04 10:58:21 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 :-)
Comment 1 Robert Ancell 2008-12-04 13:47:59 UTC
That's a really cool idea! Thanks.
Comment 2 Robin Sonefors (ozamosi) 2009-09-27 14:08:30 UTC
Created attachment 144112 [details] [review]
Add factorization function (Bug #563217)
Comment 3 Robin Sonefors (ozamosi) 2009-09-27 14:16:21 UTC
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.
Comment 4 Robin Sonefors (ozamosi) 2009-09-27 17:40:58 UTC
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.
Comment 5 Robert Ancell 2009-09-28 02:39:21 UTC
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!
Comment 6 Robert Ancell 2009-09-28 02:43:20 UTC
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.
Comment 7 Robin Sonefors (ozamosi) 2009-09-28 16:31:55 UTC
Done.

However, it creates a bit of unpleasant code, since I need a list of MPNumbers, not just one.

Please complain.
Comment 8 Robert Ancell 2009-09-28 23:07:38 UTC
No complaints.  Works well and we can look at deciding on a vector format later if we have more functions that use vectors.