Issue 122997 - Calculation error in the IMABS() function
Summary: Calculation error in the IMABS() function
Status: CLOSED FIXED
Alias: None
Product: Calc
Classification: Application
Component: code (show other issues)
Version: 4.0.0
Hardware: All All
: P3 Normal (vote)
Target Milestone: 4.0.1
Assignee: Oliver-Rainer Wittmann
QA Contact:
URL:
Keywords: regression
: 123071 (view as issue list)
Depends on:
Blocks:
 
Reported: 2013-08-09 22:28 UTC by vitriol
Modified: 2017-05-20 10:33 UTC (History)
6 users (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: Simple
jsc: 4.0.1_release_blocker+


Attachments
To be commited to branch AOO400 (770 bytes, patch)
2013-08-11 16:47 UTC, Regina Henschel
no flags Details | Diff
Test over all IMxxx functions (14.90 KB, application/vnd.oasis.opendocument.spreadsheet)
2013-08-11 16:49 UTC, Regina Henschel
no flags Details
Reworked testcases, so that a single cell shows whether the calculations have a regression (20.24 KB, application/vnd.oasis.opendocument.spreadsheet)
2013-08-25 17:35 UTC, Regina Henschel
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
Description vitriol 2013-08-09 22:28:32 UTC
There is a calculation error in the IMABS() function for complex numbers.
For example =IMABS(COMPLEX(0;5)) gives 25 as result, instead of correct value 5. Missed square root in the implementation?
It's a regression, version 3.4.1 works fine.

Thank you.
Comment 1 Regina Henschel 2013-08-09 23:39:33 UTC
Error is in scaddins/source/analysis/analysishelper.hxx  around line 833

Methode
inline double Complex::Abs( void) const
{
    return std::norm( Num );
}

should likely be
return std::abs( Num );
Comment 2 vitriol 2013-08-10 05:25:52 UTC
Thank you Regina.
This one may be related?
=IMSQRT(-4) --> 2.44948974278318+3.16227766016838i (wrong result)
Must be 2i
Comment 3 Regina Henschel 2013-08-10 12:25:50 UTC
Yes. Other functions use abs internally and are wrong too. [If nobody is faster than I, I will fix it next week.]
Comment 4 SVN Robot 2013-08-11 16:45:32 UTC
"regina" committed SVN revision 1512966 into trunk:
#i122997 Calculation error in IMABS() function
Comment 5 Regina Henschel 2013-08-11 16:47:33 UTC
Created attachment 81314 [details]
To be commited to branch AOO400
Comment 6 Regina Henschel 2013-08-11 16:49:38 UTC
Created attachment 81315 [details]
Test over all IMxxx functions

Besides rounding errors in last digit, the calculated and the expected values should be the same.
Comment 7 jsc 2013-08-13 11:57:33 UTC
approve showstopper request
Comment 8 Oliver-Rainer Wittmann 2013-08-16 11:53:55 UTC
taking over to merge Regina's fix into branch AOO401 - branch for AOO 4.0.1 release
Comment 9 SVN Robot 2013-08-19 09:26:39 UTC
"orw" committed SVN revision 1515328 into branches/AOO401:
#i122997 Calculation error in IMABS() function
Comment 10 Oliver-Rainer Wittmann 2013-08-19 09:28:07 UTC
cherry-picked Regina's fix on trunk to merge it into branch AOO401
--> issue is now fixed for AOO 4.0.1
Comment 11 Regina Henschel 2013-08-20 06:18:48 UTC
*** Issue 123071 has been marked as a duplicate of this issue. ***
Comment 12 Regina Henschel 2013-08-25 17:35:04 UTC
Created attachment 81386 [details]
Reworked testcases, so that a single cell shows whether the calculations have a regression

The testfile covers all complex functions in alphabetic order. A single cell shows whether there is a regression in calculation.
Comment 13 Kay 2013-09-01 22:38:22 UTC
Based on Regina's complete testcases doc, I am getting FALSE on the following calculation:

=IMCOS("-5+12i")


To my "eyes", the results in col C, and D are the same:

col C -- 23083.6899151345-78034.7601517634i
col D -- 23083.6899151346-78034.7601517635i

In the helper app section, the result of abs(re(B)-re(C)) is:

1.01863406598568E-010

The other helper apps jive. Maybe needs a few more tweaks?

Thanks to Regina for this great work!
Comment 14 vitriol 2013-09-02 04:34:36 UTC
(In reply to Kay from comment #13)

> To my "eyes", the results in col C, and D are the same:
> 
> col C -- 23083.6899151345-78034.7601517634i
> col D -- 23083.6899151346-78034.7601517635i

I think it's a normal floating point approximation. Seems OK to me.