Jump to content

Get Highest Value


senterpat

Recommended Posts

If the float is initialized as 0.0, and all are negative values, 0 is always going to be the highest value but, in the first iteration of my loop, the if statement will always evaluate as true for the index 0 of the array (i == 0), so it fills the variable with the first value then, in the next iterations, uses the comparison as usual.

We both have learn something from each other, I learn from you that 0 always evaluates as false.

Link to comment
Share on other sites

Best of both worlds:

Float Function GetHighestValue(float[] akValues)
  index = akValues.Length -1
  Float fHighestValue = akValues[index]
	
  While index
    index -= 1
    Float CurrentValue = akValues[index]
    If (CurrentValue > fHighestValue)
      fHighestValue = CurrentValue
    EndIf
  EndWhile
  Return fHighestValue
EndFunction

This way you do not need to check if "i" (or index) is zero in each iteration. fHighestValue starts with the last value of the array, so there is no further need to init fHighestValue with a low number which could be even not low enough.

Link to comment
Share on other sites

I couldn't replicate the results with mine, so I broke yours down to see what was being calculated differently. It seems that your i == 0 check allows your function to account for negative values without initializing the variable to a high negative value first. I remember when I first wrote that code some years back and I couldn't get around the issue without first making the variable a high negative number.

 

I don't get the problem :huh:

From CreationKit.com literal reference guide:

 

Floats are 32-bits in size, and have a range of 1.175494351 E – 38 to 3.402823466 E + 38 with 7 significant digits. They match the IEEE standard single type (23+1 significant bits and 8 exponent bits).

 

As the standard, a signed Float should handle the limited negative values fine. So why do you think DieFeM's function wouldn't handle negative values and find the highest? :mellow:

 

-34f > 24f == false

-34f < 24f == true

 

On a side note, is the 'i++' incrementer not available in Papyrus? :sad:

Link to comment
Share on other sites

Oh I think I get the thought process now lol. Didn't see the second page :ermm:

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...