mulesoft-labs / data-weave-rfc

RFC for the data weave language
13 stars 5 forks source link

Getting NaN error when using binary operator with Math log10 and logn functions #60

Open pranav-davar opened 7 months ago

pranav-davar commented 7 months ago

with code

%dw 2.0
output application/json
import * from dw::util::Math
---
logn(2)/logn(5)

Getting output as

Unable to call: `/` with arguments: (`Number | NaN`, `Number | NaN`).
 Reasons:
    - Expecting Type: `Number`, but got: `NaN`.
        |-- From: `Number`  
        |- From: /(lhs: Number, rhs: Number) -> Number      
            439| fun logn(a: Number): Number | NaN = native("system::LognFunctionValue")
                                               ^^^
    - Expecting Type: `Number`, but got: `NaN`.
        |-- From: `Number`  
        |- From: /(lhs: Number, rhs: Number) -> Number      
            439| fun logn(a: Number): Number | NaN = native("system::LognFunctionValue")
                                               ^^^
    - 1 more options ...

5| logn(2)/logn(5)
   ^^^^^^^^^^^^^^^
Location:
main (line: 5, column:1)

But typeOf(logn(2)) is "Number"

If we do type casting then it is working. Type casting should not be required if the type is already Number.

The below codes work fine

%dw 2.0
output application/json
import * from dw::util::Math
---
logn(2) as Number/logn(5) as Number