@@ -415,38 +415,50 @@ static QVariant fcnExpScale( const QVariantList &values, const QgsExpressionCont
415415
416416static QVariant fcnMax ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
417417{
418- // initially set max as first value
419- double maxVal = QgsExpressionUtils::getDoubleValue ( values.at ( 0 ), parent );
420-
421- // check against all other values
422- for ( int i = 1 ; i < values.length (); ++i )
418+ QVariant result ( QVariant::Double );
419+ double maxVal = std::numeric_limits<double >::quiet_NaN ();
420+ for ( const QVariant &val : values )
423421 {
424- double testVal = QgsExpressionUtils::getDoubleValue ( values[i] , parent );
425- if ( testVal > maxVal )
422+ double testVal = val. isNull () ? std::numeric_limits< double >:: quiet_NaN () : QgsExpressionUtils::getDoubleValue ( val , parent );
423+ if ( std::isnan ( maxVal ) )
426424 {
427425 maxVal = testVal;
428426 }
427+ else if ( !std::isnan ( testVal ) )
428+ {
429+ maxVal = std::max ( maxVal, testVal );
430+ }
429431 }
430432
431- return QVariant ( maxVal );
433+ if ( !std::isnan ( maxVal ) )
434+ {
435+ result = QVariant ( maxVal );
436+ }
437+ return result;
432438}
433439
434440static QVariant fcnMin ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
435441{
436- // initially set min as first value
437- double minVal = QgsExpressionUtils::getDoubleValue ( values.at ( 0 ), parent );
438-
439- // check against all other values
440- for ( int i = 1 ; i < values.length (); ++i )
442+ QVariant result ( QVariant::Double );
443+ double minVal = std::numeric_limits<double >::quiet_NaN ();
444+ for ( const QVariant &val : values )
441445 {
442- double testVal = QgsExpressionUtils::getDoubleValue ( values[i] , parent );
443- if ( testVal < minVal )
446+ double testVal = val. isNull () ? std::numeric_limits< double >:: quiet_NaN () : QgsExpressionUtils::getDoubleValue ( val , parent );
447+ if ( std::isnan ( minVal ) )
444448 {
445449 minVal = testVal;
446450 }
451+ else if ( !std::isnan ( testVal ) )
452+ {
453+ minVal = std::min ( minVal, testVal );
454+ }
447455 }
448456
449- return QVariant ( minVal );
457+ if ( !std::isnan ( minVal ) )
458+ {
459+ result = QVariant ( minVal );
460+ }
461+ return result;
450462}
451463
452464static QVariant fcnAggregate ( const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction * )
@@ -3937,8 +3949,8 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
39373949 sFunctions << randfFunc;
39383950
39393951 sFunctions
3940- << new QgsStaticExpressionFunction ( QStringLiteral ( " max" ), -1 , fcnMax, QStringLiteral ( " Math" ) )
3941- << new QgsStaticExpressionFunction ( QStringLiteral ( " min" ), -1 , fcnMin, QStringLiteral ( " Math" ) )
3952+ << new QgsStaticExpressionFunction ( QStringLiteral ( " max" ), -1 , fcnMax, QStringLiteral ( " Math" ), QString (), false , QSet<QString>(), false , QStringList (), /* handlesNull = */ true )
3953+ << new QgsStaticExpressionFunction ( QStringLiteral ( " min" ), -1 , fcnMin, QStringLiteral ( " Math" ), QString (), false , QSet<QString>(), false , QStringList (), /* handlesNull = */ true )
39423954 << new QgsStaticExpressionFunction ( QStringLiteral ( " clamp" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " min" ) ) << QgsExpressionFunction::Parameter ( QStringLiteral ( " value" ) ) << QgsExpressionFunction::Parameter ( QStringLiteral ( " max" ) ), fcnClamp, QStringLiteral ( " Math" ) )
39433955 << new QgsStaticExpressionFunction ( QStringLiteral ( " scale_linear" ), 5 , fcnLinearScale, QStringLiteral ( " Math" ) )
39443956 << new QgsStaticExpressionFunction ( QStringLiteral ( " scale_exp" ), 6 , fcnExpScale, QStringLiteral ( " Math" ) )
0 commit comments