@@ -118,6 +118,16 @@ public Operand VisitAddSub_fun([NotNull] mathParser.AddSub_funContext context)
118118 var t = context . op . Text ;
119119
120120 if ( t == "&" ) {
121+ if ( firstValue . IsNull && secondValue . IsNull ) {
122+ return firstValue ;
123+ } else if ( firstValue . IsNull ) {
124+ secondValue = secondValue . ToString ( $ "Function '{ t } ' parameter 2 is error!") ;
125+ return secondValue ;
126+ } else if ( secondValue . IsNull ) {
127+ firstValue = firstValue . ToString ( $ "Function '{ t } ' parameter 1 is error!") ;
128+ return firstValue ;
129+ }
130+
121131 firstValue = firstValue . ToString ( $ "Function '{ t } ' parameter 1 is error!") ;
122132 if ( firstValue . IsError ) { return secondValue ; }
123133 secondValue = secondValue . ToString ( $ "Function '{ t } ' parameter 2 is error!") ;
@@ -187,6 +197,20 @@ public Operand VisitJudge_fun([NotNull] mathParser.Judge_funContext context)
187197 var secondValue = args [ 1 ] ;
188198 string type = context . op . Text ;
189199
200+ if ( firstValue . IsNull ) {
201+ if ( secondValue . IsNull && ( type == "==" || type == "=" ) ) {
202+ return Operand . True ;
203+ } else if ( secondValue . IsNull == false && ( type == "<>" || type == "!=" ) ) {
204+ return Operand . True ;
205+ }
206+ return Operand . False ;
207+ } else if ( secondValue . IsNull ) {
208+ if ( type == "==" || type == "=" ) {
209+ return Operand . False ;
210+ }
211+ return Operand . True ;
212+ }
213+
190214 int r ;
191215 if ( firstValue . Type == secondValue . Type ) {
192216 if ( firstValue . Type == OperandType . STRING || firstValue . Type == OperandType . JSON ) {
@@ -315,7 +339,6 @@ public Operand VisitIFERROR_fun([NotNull] mathParser.IFERROR_funContext context)
315339 return args [ 2 ] ;
316340 }
317341 return Operand . False ;
318-
319342 }
320343 public Operand VisitISNUMBER_fun ( [ NotNull ] mathParser . ISNUMBER_funContext context )
321344 {
@@ -339,8 +362,50 @@ public Operand VisitISTEXT_fun([NotNull] mathParser.ISTEXT_funContext context)
339362 }
340363 public Operand VisitISERROR_fun ( [ NotNull ] mathParser . ISERROR_funContext context )
341364 {
342- var firstValue = this . Visit ( context . expr ( ) ) ;
343- if ( firstValue . Type == OperandType . ERROR ) {
365+ var args = new List < Operand > ( ) ;
366+ foreach ( var item in context . expr ( ) ) { var aa = this . Visit ( item ) ; args . Add ( aa ) ; }
367+ if ( args . Count == 2 ) {
368+ if ( args [ 0 ] . IsError ) {
369+ return args [ 1 ] ;
370+ }
371+ return args [ 0 ] ;
372+ }
373+
374+ if ( args [ 0 ] . IsError ) {
375+ return Operand . True ;
376+ }
377+ return Operand . False ;
378+ }
379+
380+ public Operand VisitISNULL_fun ( [ NotNull ] mathParser . ISNULL_funContext context )
381+ {
382+ var args = new List < Operand > ( ) ;
383+ foreach ( var item in context . expr ( ) ) { var aa = this . Visit ( item ) ; args . Add ( aa ) ; }
384+
385+ if ( args . Count == 2 ) {
386+ if ( args [ 0 ] . IsNull ) {
387+ return args [ 1 ] ;
388+ }
389+ return args [ 0 ] ;
390+ }
391+ if ( args [ 0 ] . IsNull ) {
392+ return Operand . True ;
393+ }
394+ return Operand . False ;
395+ }
396+
397+ public Operand VisitISNULLORERROR_fun ( [ NotNull ] mathParser . ISNULLORERROR_funContext context )
398+ {
399+ var args = new List < Operand > ( ) ;
400+ foreach ( var item in context . expr ( ) ) { var aa = this . Visit ( item ) ; args . Add ( aa ) ; }
401+
402+ if ( args . Count == 2 ) {
403+ if ( args [ 0 ] . IsNullOrError ) {
404+ return args [ 1 ] ;
405+ }
406+ return args [ 0 ] ;
407+ }
408+ if ( args [ 0 ] . IsNullOrError ) {
344409 return Operand . True ;
345410 }
346411 return Operand . False ;
@@ -2744,17 +2809,17 @@ private double F_base_sumif(List<double> dbs, string s, List<double> sumdbs)
27442809 private bool F_base_compare ( double a , double b , string ss )
27452810 {
27462811 if ( ss == "<" ) {
2747- return Math . Round ( a , 12 , MidpointRounding . AwayFromZero ) < Math . Round ( b , 12 , MidpointRounding . AwayFromZero ) ;
2812+ return Math . Round ( a - b , 12 , MidpointRounding . AwayFromZero ) < 0 ;
27482813 } else if ( ss == "<=" ) {
2749- return Math . Round ( a , 12 , MidpointRounding . AwayFromZero ) <= Math . Round ( b , 12 , MidpointRounding . AwayFromZero ) ;
2814+ return Math . Round ( a - b , 12 , MidpointRounding . AwayFromZero ) <= 0 ;
27502815 } else if ( ss == ">" ) {
2751- return Math . Round ( a , 12 , MidpointRounding . AwayFromZero ) > Math . Round ( b , 12 , MidpointRounding . AwayFromZero ) ;
2816+ return Math . Round ( a - b , 12 , MidpointRounding . AwayFromZero ) > 0 ;
27522817 } else if ( ss == ">=" ) {
2753- return Math . Round ( a , 12 , MidpointRounding . AwayFromZero ) >= Math . Round ( b , 12 , MidpointRounding . AwayFromZero ) ;
2818+ return Math . Round ( a - b , 12 , MidpointRounding . AwayFromZero ) >= 0 ;
27542819 } else if ( ss == "=" || ss == "==" ) {
2755- return Math . Round ( a , 12 , MidpointRounding . AwayFromZero ) == Math . Round ( b , 12 , MidpointRounding . AwayFromZero ) ;
2820+ return Math . Round ( a - b , 12 , MidpointRounding . AwayFromZero ) == 0 ;
27562821 }
2757- return Math . Round ( a , 12 , MidpointRounding . AwayFromZero ) != Math . Round ( b , 12 , MidpointRounding . AwayFromZero ) ;
2822+ return Math . Round ( a - b , 12 , MidpointRounding . AwayFromZero ) != 0 ;
27582823 }
27592824
27602825 private bool F_base_GetList ( List < Operand > args , List < double > list )
@@ -3602,6 +3667,10 @@ public Operand VisitSTRING_fun([NotNull] mathParser.STRING_funContext context)
36023667 }
36033668 return Operand . Create ( sb . ToString ( ) ) ;
36043669 }
3670+ public Operand VisitNULL_fun ( [ NotNull ] mathParser . NULL_funContext context )
3671+ {
3672+ return Operand . CreateNull ( ) ;
3673+ }
36053674 public Operand VisitPARAMETER_fun ( [ NotNull ] mathParser . PARAMETER_funContext context )
36063675 {
36073676 var p = this . Visit ( context . parameter ( ) ) . ToString ( "Function PARAMETER first parameter is error!" ) ;
@@ -3664,6 +3733,7 @@ public Operand VisitGetJsonValue_fun([NotNull] mathParser.GetJsonValue_funContex
36643733 if ( v . IsLong ) return Operand . Create ( double . Parse ( v . ToString ( ) , NumberStyles . Any , cultureInfo ) ) ;
36653734 if ( v . IsObject ) return Operand . Create ( v ) ;
36663735 if ( v . IsArray ) return Operand . Create ( v ) ;
3736+ if ( v . IsNull ) return Operand . CreateNull ( ) ;
36673737 return Operand . Create ( v ) ;
36683738 }
36693739 return Operand . Error ( $ "JSON index { index } greater than maximum length!") ;
@@ -3680,6 +3750,7 @@ public Operand VisitGetJsonValue_fun([NotNull] mathParser.GetJsonValue_funContex
36803750 if ( v . IsLong ) return Operand . Create ( double . Parse ( v . ToString ( ) , NumberStyles . Any , cultureInfo ) ) ;
36813751 if ( v . IsObject ) return Operand . Create ( v ) ;
36823752 if ( v . IsArray ) return Operand . Create ( v ) ;
3753+ if ( v . IsNull ) return Operand . CreateNull ( ) ;
36833754 return Operand . Create ( v ) ;
36843755 }
36853756 }
@@ -3695,6 +3766,7 @@ public Operand VisitExpr2_fun([NotNull] mathParser.Expr2_funContext context)
36953766
36963767
36973768
3769+
36983770 #endregion
36993771 }
37003772}
0 commit comments