MiniSnap & MAX() function with 3 argument?

Forums: 

To all

I am using MiniSnap to access some basic Math function. I do not have the full SNP licence.
I am using SQRT and MAX. Both seem to work OK but I have a problem with the Max() function with 3 arguments as NX crashes. it works with 2 arguments!

I have

If Math.Max(dXmass,dYmass,dZmass) < TheEffMassThreshold Then....
where the input are Double

Any idea what is the cause of the problem?

Thanks
Regards
JXB

The .NET Math.Max function only takes two arguments and returns the larger one. The SNAP .Max function only takes a single argument, an array of values, and returns the largest one in the array. Neither version of the function accepts three arguments.

It appears that you will only ever have three values to compare (X, Y, and Z). If this is the case, a straightforward way to get the Max is simply calling the .Max function twice:

Dim largest as double
'compare the larger of X and Y to Z
largest = Math.Max(dXmass, dYmass)
largest = Math.Max(largest, dZmass)

'or, combining the above into one line of code
largest = Math.Max(Math.Max(dXmass, dYmass), dZmass)

Thanks for the clarification. The example in the SNAP manual shows: Max(-5,1,3) so it's a bit misleading
Will probably due a double "check" to get the max as shown in the combining method provided

Thanks
Regards

The specs of the Snap.Math.Max function are:

Public Shared Function Max (ParamArray values As Double() ) As Double

The "ParamArray" thing means you can pass a sequence of individual values, rather than composing them into an array.

Here are some examples of how to do what you want (and how not to do it):

Imports System.Linq

Public Class MyProgram

Public Shared Sub Main()

Dim doubleArray As Double() = {-5.0, 1.0, 3.0}

' Using System.Linq -- works
Dim max1 As Double = doubleArray.Max

' Using Snap.Math.Max with an array -- works
Dim max2 As Double = Snap.Math.Max(doubleArray)

' Using Snap.Math.Max with individual arguments -- works
Dim max3 As Double = Snap.Math.Max(-5.0, 1.0, 3.0)

' This fails because it calls System.Math.Max
Dim max4 As Double = Math.Max(doubleArray)

' This fails because there is no MiniSnap.Math
Dim max5 As Double = MiniSnap.Math.Max(doubleArray)

End Sub

End Class