Getting Err:502 with complex number functions

I am using Ubuntu 16.04 and LibreOffice 5.2. Some of my spreadsheets rely on complex numbers and I am getting Err: 502 in the cells. These spreadsheets were working well with Ubuntu 14.04 and also run without issues on a Windows 10 platform. The behavior is strange as I will get Err:502 with a simple function “=IMSUM(A1, B2)” so there is no syntax error, however if I re-enter the formula the calculation works. When if I come back to the spreadsheet the cells will again show Err:502. Also a user-defined function that uses complex numbers and has worked for years, no longer works and a message box shows up
“BASIC runtime error.
An exception occurred
Message: .”
(Editing:) I upvoted your question to see that the force be with you. Please upload a relevant example file.

Do you have an example, i.e. what strings are in A1 and B2?

A1 and B2 are just two cells at least one of which contains a complex number.

Here is the user-defined function:

function IMPARA(x,y) 
arg2=array(pr,su) impara=svc.callFunction("IMDIV",arg2) 
end function 

x and y are cells where either one or both are complex numbers. The routine locks at 4th line (“pr= …”)

From the OQ: I will get Err:502 with a simple function “=IMSUM(A1, B2)” so there is no syntax error,
Compare with the statement from the comment.
Are you (@sliner) mucking around?
Edit your question and attach a thoroughly prepared example!

Why would I waste my and your time by “mucking around”. I tried pasting a screenshot of a portion of the spreadsheet in the comment but it doesn’t seem to work. I am new to this forum. Any suggestions on how to do this?

@sliner: Sorry if my words were too harsh.Due to my poor English I often fail to find the proper terms.
There is a tool in the toolbar for making attachments. It is only available when writing/editing questions/answers, not for comments.
Do not attach screenshots but the real thing wherever feasible, please. In this case it would be a tiny spreadsheet document, I think.

Here is an example from a spreadsheet:
A cell contains the formula “=IMABS(AH5)” where AH5 is a cell with a complex number. The cell in question shows “Err:502”. I get similar results in other cells that use complex number functions such as IMSUM or IMDIV. As I said it is not an error in syntax or improper entry but an issue using LibreOffice 5.2 with Ubuntu 16.04.

You surely looked up the meaning of “Err:502”. With respect to your recent example the next step must be to inspect cell AH5 for a probable reason to get that error. It would save us hours if you finally attached a spreadsheet document showing the error for you. What’s the problem with this?
I spent the time to prepare and attach an example and you don’t even tell me how it worked on your system.

Unfortunately your IMPARA example still does not answer my question what the actual values/strings in A1 and B2 are. Same for IMABS(AH5), what is the content of AH5? For example, =IMABS("1.2+3.4i") works fine for me and results in 3.60555127546399, also =IMSUM("1.2+3.4i","5.6+7.8i") that results in “6.8+11.2i”
Also your macro example works for me (after splitting the second but last line in two), =IMSUM("1.2+3.4i","5.6+7.8i") results in “1.06849953401678+2.4165890027959i”.

Do you actually want to calculate half of the “harmonic mean” of two complex numbers contained in A1, B2?
Why not use
in the respective cell?
In fact the user function also works. The BASIC code as posted contained a syntactical error: Two statements in one line without a statement delimiter.
(Editing with respect to the comments:)
I made this little demonstration of the Calc formula I suggested and the application of the code from the OQ as well. Both are working flawlessly here (LibO 5.2.2 on Win 10). I would prefer the formula and expect to get higher efficiency by that. Some variant of Copy/Paste should allow for omitting too much of typing.
(A last attempt:)
Another little demonstration.

I wanted to replace the expression with something simpler to type as I use it quite a lot. The syntactical error was created when I pasted the macro. In fact each statement does have it’s own line. Regardless the problem seems to be the use of complex number functions. I As I mentioned these are old spreadsheets that have been working for years until I began using Ubuntu 16.04 and still work on a Windows 10 platform.

Sorry. I cannot test with Ubuntu. (In fact I am afraid that silly Win I need for some special reason on my sole computer will get angry with me if I try another dual boot.)

VirtualBox with guest additions is an option.