4 Replies Latest reply on Apr 4, 2013 10:21 AM by disabled_ntaylor

    ? (NaN/NotANumber) is incorrectly passed to CFs

      Summary

      ? (NaN/NotANumber) is incorrectly passed to CFs

      Product

      FileMaker Pro

      Version

      FM11 and fmp12

      Operating system version

      Mac  and Win

      Description of the issue

      It is not possible to write a custom function to correctly test for '?' (NaN)!

      When a calculation returns an invalid result (e.g. 1/0) or a custom function does not end filemaker returns a question mark: ? (which represents an error much like NaN 'not-a-number' in other programming languages).

      The FileMaker function IsValid( expression ) returns 0 ('invalid') if the expression is invalid, i.e. a ? However, if the IsValid function is performed within a custom function on a parameter *containing the same expression*, it incorrectly returns a 1 ('valid').

      It appears to be the PASSING of the parameter which is faulty, because IsValid( 1/0 ) inside a custom function correctly returns a zero.
      The passed ? appears to work in all other respects inide the CF:
      adding 1 to the passed ? inside the CF correctly returns ?
      testing pParam > 0 on the passed ? inside the CF correctly returns 1

      ---
      Background:
      We tried to test the results of our custom functions with the following:

      Let( vResult = SomeCustomFunctionCall( foo );
      Case( vResult > 0 ; process result here
      )

      however, the NaN ? is bigger than 0 (maybe +infinity?). We could change it to:

      Let( vResult = SomeCustomFunctionCall( foo );
      Case( IsValid( vResult ) and vResult > 0 ; process result here
      )

      but that is ugly/difficult to read/not DRY. Thus we wish to make a custom function 'ValidResult( Result )' to test the results of a calculation, e.g.:

      Let( vResult = SomeCustomFunctionCall( foo );
      Case( ValidResult( vResult ) ; process result here
      )

      BUT...there's an FM bug! :(

      Steps to reproduce the problem

      1) Create a custom function TestNaNinCF = IsValid( 1/0 )
      2) Create a custom function TestParameterNaN( n ) = IsValid( n )
      3) Enter the following expressions into the dataviewer:

      1/0
      IsValid( 1/0 )
      TestNaNinCF
      TestParameterNaN( 1/0 )

      Expected result

      1/0 -> ?
      IsValid( 1/0 ) -> 0
      TestNaNinCF -> 0
      TestParameterNaN( 1/0 ) -> 0

      Actual result

      1/0 -> ?
      IsValid( 1/0 ) -> 0
      TestNaNinCF -> 0
      TestParameterNaN( 1/0 ) -> 1

      Exact text of any error message(s) that appear

      -

      Configuration information

      -

      Workaround

      Inside the custom function you can use the following to test for an invalid parameter

      Case( pParam="?" and pParam > 0 ; "invalid" ; "valid" )

      Bildschirmfoto_2012-10-08_um_14.20.35.png