Hi Everybody,
I am trying to compare single precision floating point values in VB .NET. The code runs ok but the results look not right. Results also contain -Inf values. I see that this is not the right way of comparing floating points. Could you please show me how to compare these? Thank you so much.

For m = 0 To fLen1 - 1 
                If snglRead1(m) >= -1.0 And snglRead1(m) <= -0.18 Then
                    snglOutput(m) = 0.985
                ElseIf snglRead1(m) > -0.18 And snglRead1(m) <= 0.157 Then
                    snglOutput(m) = 0.955
                ElseIf snglRead1(m) > 0.157 And snglRead1(m) <= 0.727 Then
                    snglOutput(m) = Math.Log(snglOutput(m))
                ElseIf snglRead1(m) > 0.727 And snglRead1(m) <= 1.0 Then
                    snglOutput(m) = 0.99
                End If
                bw.Write(snglOutput(m))
            Next

fLen1 is the length of the file that has been read. The file has floating point values between -1.0 and +1.0

Hmm, I asked the wrong question, I meant: what does the function snglRead1() do? Do you have the code for it?
I'm guessing the function reads one float from a file? If thats the case, then this line:

If snglRead1(m) >= -1.0 And snglRead1(m) <= -0.18

will probably read the first and second number from the file and compare the two. This is not what you want, so read one float and store it in a variable. Then compare it to your values.

Edited 5 Years Ago by Nick Evan: n/a

snglRead1(m) is an array and it is in a for next loop so that it compares array index with the cell value then assignes it to some constant value... There is no reading on the code that I posted.

This article has been dead for over six months. Start a new discussion instead.