Bug 495232 - Errors with scientific notation
Summary: Errors with scientific notation
Status: REPORTED
Alias: None
Product: kcalc
Classification: Applications
Component: general (other bugs)
Version First Reported In: 24.08.0
Platform: openSUSE Linux
: NOR normal
Target Milestone: ---
Assignee: Gabriel Barrantes
URL:
Keywords:
: 496412 (view as bug list)
Depends on:
Blocks:
 
Reported: 2024-10-23 09:23 UTC by Wolfram Klaus
Modified: 2024-11-18 15:53 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
gnome-calculator (65.05 KB, image/png)
2024-10-23 13:46 UTC, Gabriel Barrantes
Details
show keys on genome calculator (56.37 KB, image/png)
2024-10-23 15:24 UTC, Gabriel Barrantes
Details
Dividing Planck by Planck per button (34.40 KB, image/png)
2024-10-23 16:06 UTC, Wolfram Klaus
Details
Dividing Planck by Planck per h-key (32.85 KB, image/png)
2024-10-23 16:06 UTC, Wolfram Klaus
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Wolfram Klaus 2024-10-23 09:23:13 UTC
SUMMARY
Calculations with numbers in scientific notation yield wrong results

STEPS TO REPRODUCE
1.  3e8/3e8 -> 1E16 (should be 1)
2.  3e8² -> 3E16 (should be 9E16)
3. Builtin Constants work fine though

OBSERVED RESULT
Numbers entered in scientific notation (either using keyboard E or the correspondig button) are not treated as ONE number in mantissa/exponent-from, but as a product of a simple number and a power of ten.
This is contrary to all calculators out there (including older versions of kcalc).

EXPECTED RESULT


SOFTWARE/OS VERSIONS
Windows: 
macOS: 
(available in the Info Center app, or by running `kinfo` in a terminal window)
Linux/KDE Plasma: 
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION
Comment 1 Gabriel Barrantes 2024-10-23 13:44:36 UTC
I am getting "3e8/3e8 = 1", I guess you are getting "3⏨8/3⏨8 = 1e+16", but this would be expected as the "⏨" is actually "*10^" so it does "3*10^8/3*10^8". Actually gnome calculator does the same, check the screenshot attached.
Comment 2 Gabriel Barrantes 2024-10-23 13:46:30 UTC
Created attachment 175141 [details]
gnome-calculator

I could check other calculators, but this makes sense given the precedence of the operators.
Comment 3 Wolfram Klaus 2024-10-23 14:28:09 UTC
(In reply to Gabriel Barrantes from comment #1)
> I am getting "3e8/3e8 = 1", I guess you are getting "3⏨8/3⏨8 = 1e+16", but
> this would be expected as the "⏨" is actually "*10^" so it does
> "3*10^8/3*10^8". Actually gnome calculator does the same, check the
> screenshot attached.

It is the expected behaviour to get 1E16 if you type "*" "1" "0" "^", because the "*" is an operator of equal precedence with /.

It is not the expected behaviour of the "*10^" key. This key has been in use for decades on calculators (including kcalc) to enter numbers in scientific notation without the need to surround them by braces. It is supposed to behave like 3E8 in most programming languages:

#include <stdio.h>
int main()
{
  float one=3E8/3E8;
  printf("%f", one);
}
prints  1.000000 on the terminal, as it should.

I just installed gnome-calculator, I couldn't even find the "*10^" key.
Comment 4 Gabriel Barrantes 2024-10-23 15:24:05 UTC
Created attachment 175147 [details]
show keys on genome calculator
Comment 5 Gabriel Barrantes 2024-10-23 15:56:50 UTC
(In reply to Wolfram Klaus from comment #3)
> (In reply to Gabriel Barrantes from comment #1)
> > I am getting "3e8/3e8 = 1", I guess you are getting "3⏨8/3⏨8 = 1e+16", but
> > this would be expected as the "⏨" is actually "*10^" so it does
> > "3*10^8/3*10^8". Actually gnome calculator does the same, check the
> > screenshot attached.
> 
> It is the expected behaviour to get 1E16 if you type "*" "1" "0" "^",
> because the "*" is an operator of equal precedence with /.
> 
> It is not the expected behaviour of the "*10^" key. This key has been in use
> for decades on calculators (including kcalc) to enter numbers in scientific
> notation without the need to surround them by braces. It is supposed to
> behave like 3E8 in most programming languages:
> 
> #include <stdio.h>
> int main()
> {
>   float one=3E8/3E8;
>   printf("%f", one);
> }
> prints  1.000000 on the terminal, as it should.
> 
> I just installed gnome-calculator, I couldn't even find the "*10^" key.

check the second attachment, there is a small button there with ... that will show the button on the gnome calculator.

Either way, inputs like "3E8/3E8" actually result in 1, the problem I guess is that the button is doing "*10^" and not "e" or "E" and that from the mathematical sense is not the same.

I just checked Qalculate and they are inserting "e" instead of "*10^", and the button label is "EXP" and not "*10^y", that could be an option, I guess that people expect having the scientific notation take precedence even tho it shouldn't (definitely should't when using *10^).

For now the button is doing what it should,  we could change it to be "e", but let's wait to see if someone else reports the same.
Comment 6 Wolfram Klaus 2024-10-23 15:59:14 UTC
(In reply to Gabriel Barrantes from comment #4)
> Created attachment 175147 [details]
> show keys on genome calculator

OK, found it and could reproduce that gnome-calculator gets it wrong, too.
Kcalc at least gets it right with builtin constants. Try typing this on the keyboard to play with Planck's constant
h -> 6,62607015e-34 
h/h -> 1

It even works if you assign Planck's constant to a Button, so that pressing the button inserts its value

(see attachments)
Comment 7 Wolfram Klaus 2024-10-23 16:06:03 UTC
Created attachment 175150 [details]
Dividing Planck by Planck per button
Comment 8 Wolfram Klaus 2024-10-23 16:06:53 UTC
Created attachment 175151 [details]
Dividing Planck by Planck per h-key
Comment 9 Gabriel Barrantes 2024-10-23 16:34:38 UTC
(In reply to Wolfram Klaus from comment #6)
> (In reply to Gabriel Barrantes from comment #4)
> > Created attachment 175147 [details]
> > show keys on genome calculator
> 
> OK, found it and could reproduce that gnome-calculator gets it wrong, too.
> Kcalc at least gets it right with builtin constants. Try typing this on the
> keyboard to play with Planck's constant
> h -> 6,62607015e-34 
> h/h -> 1
> 
> It even works if you assign Planck's constant to a Button, so that pressing
> the button inserts its value
> 
> (see attachments)

yeah, as I said, using "e" or "E" works fine, but is not the same as "*10^", so is not a bug, we could change it to be "e" instead of "*10^" but let's wait if someone else reports the issue.
For now you can just focus the input display (click on it) and type "e".
Comment 10 Wolfram Klaus 2024-10-24 11:44:13 UTC
(In reply to Gabriel Barrantes from comment #9)
> (In reply to Wolfram Klaus from comment #6)
> > (In reply to Gabriel Barrantes from comment #4)
> > > Created attachment 175147 [details]
> > > show keys on genome calculator
> > 
> > OK, found it and could reproduce that gnome-calculator gets it wrong, too.
> > Kcalc at least gets it right with builtin constants. Try typing this on the
> > keyboard to play with Planck's constant
> > h -> 6,62607015e-34 
> > h/h -> 1
> > 
> > It even works if you assign Planck's constant to a Button, so that pressing
> > the button inserts its value
> > 
> > (see attachments)
> 
> yeah, as I said, using "e" or "E" works fine, but is not the same as "*10^",
> so is not a bug, we could change it to be "e" instead of "*10^" but let's
> wait if someone else reports the issue.
> For now you can just focus the input display (click on it) and type "e".

OK, focussing the input display and using e works as I expect it. Thank you very much. Now I can work with kcalc like I used to.
Following are some thoughts you might consider or not even read;-)

History of the button:
Desktop calculators eg. from Casio, TI, etc. used to have a button for entering scientific notation, which was labeled  "EE" or "EXP" for decades. About 10-15 years ago they changed the label of the button to "·10^x", probably to be more student friendly. The meaning stayed the same.

Usage of the button:
I as a physics teacher use and tell my students to use this button a) to enter big or small numbers like the mass of the earth or of an oil drop in Millikan's experiment and b) to enter values with SI prefixes like 1.8 GHz or 632.8 nm. 
When working with formulae such as Newton's F=GmM/r² with r=149.6·10^9m it is nice, when this value is treated as one number like on a Casio, TI, etc.
Actually I have never come across a use case, where I wanted to divide one number by another and multiply the result by a pure power of 10. In such a case, what kcalc and gnome calculator do right now would indeed be handy. 
I think the reason why calculators have have this button and not a "·9^x" or a "+3)·x" button, is because it is intended for entering scientific notation and not as a shortcut... 

Mathematical correctness:
No doubt, you are mathematically correct. On the other hand there is this thing with SI prefixes: 1km² are per definition 10^6m² which actually contradicts order of precedence, but it is the way powers of units with SI prefixes are handled. One might consider the Interpretation of  
button as in line with this.

What to do?
a) I am happy with the solution you gave me. So you can close this bug report (if no one else reports this issue, as you said)
b) Change the behavior and wait if someone reports a bug;-)
c) Make the behavior configurable
d) Offer both buttons

Oh, and thanks for your work on Open Source Software!
Comment 11 Gabriel Barrantes 2024-11-18 15:53:21 UTC
*** Bug 496412 has been marked as a duplicate of this bug. ***