elementary / applications-menu

Applications Menu for elementary OS and the Pantheon desktop environment
https://elementary.io
GNU General Public License v3.0
104 stars 36 forks source link

Surprising exponentiation thanks to bc in calculator plugin #115

Open joseph-long opened 6 years ago

joseph-long commented 6 years ago

While poking around for #114 I realized you can't do a square root with the sqrt() function. But more than that, trying to do it as a fractional exponent gives a surprising result :joy:

image

peteruithoven commented 6 years ago

Looks like an issue with bc:

$ bc
bc 1.07.1
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'. 
2^(1 / 2)
1

qalc seems to handle this better:

$ qalc '2^(1/2)'
2^(1 / 2) = approx. 1,4142136

One challenge with functions like sqrt() is that the applications-menu plugin needs to determine what looks like a measurement before it actually performs the calculation. See: https://github.com/elementary/applications-menu/blob/master/lib/synapse-plugins/calculator-plugin.vala#L66-L72