strange result in multiplying empty cells

I am using Calc
“Version: 6.1.5.2
Build ID: 1:6.1.5-3
CPU threads: 12; OS: Linux 4.19; UI render: default; VCL: gtk3_kde5;
Locale: en-US (en_US.UTF-8); Calc: group threaded”.

I am practicing with building and using customer function, and as a first step I inserted the sample function

Function VOL(a, b, c)  
VOL = a*b*c  
End Function

in My Macros & Dialogs/Standard/Module1.
I went and use it in a worksheet, and by accident included in the computation a blank cell with two other containing 2 and 4: the result was 8 (!?).
I then tried with all the three cells empty, and the result was an empty cell.
Multiplying the cells normally (=A1*A2) I get 0 if one cell is empty, as expected.

So, I cannot grasp what’s going on with the function: is it a bug ? any other reason

Hello @giul51

Your code does not set types for variables used and for return value, so that is why you can get an unexpected result in some use cases. When an empty cell is passed in your function, the value of corresponding variable is not set to 0, but to empty value, thus ignored by a*b*c expression. It is much more better to declare expected variable types, so your code is less error prone. Something like this is better, but it will return 0 if any of cell used is a text string:

Function VOL (a as Double, b as Double, c as Double) as Double
VOL = a*b*c
End Function

Thanks @SM_Riga for your answer. So, as I understand, such a behaviour is not a bug but a designed feature that an empty variant is not converted to 0 , as in the spreadsheet, nor “mathematically” converted to empty (0 in sums, and to 1 in multiplications). Well, that’s worthy to be well understood known. Thanks again

Looks like tdf#124605, a Basic error with an empty variant.

Thanks for your answer: in fact it is the same problem.