How to compare floating point values

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2007
Posts: 19
Reputation: cs_tx_usa is an unknown quantity at this point 
Solved Threads: 0
cs_tx_usa's Avatar
cs_tx_usa cs_tx_usa is offline Offline
Newbie Poster

How to compare floating point values

 
0
  #1
Mar 3rd, 2008
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.

  1. For m = 0 To fLen1 - 1
  2. If snglRead1(m) >= -1.0 And snglRead1(m) <= -0.18 Then
  3. snglOutput(m) = 0.985
  4. ElseIf snglRead1(m) > -0.18 And snglRead1(m) <= 0.157 Then
  5. snglOutput(m) = 0.955
  6. ElseIf snglRead1(m) > 0.157 And snglRead1(m) <= 0.727 Then
  7. snglOutput(m) = Math.Log(snglOutput(m))
  8. ElseIf snglRead1(m) > 0.727 And snglRead1(m) <= 1.0 Then
  9. snglOutput(m) = 0.99
  10. End If
  11. bw.Write(snglOutput(m))
  12. Next
“Remember: If you’re not experiencing failure, you’re not working hard enough!”
Jeffrey J. Mayer
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,839
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 298
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is online now Online
Roasting Maven

Re: How to compare floating point values

 
0
  #2
Mar 3rd, 2008
What is fLen? What values can it contain? Give an example.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 19
Reputation: cs_tx_usa is an unknown quantity at this point 
Solved Threads: 0
cs_tx_usa's Avatar
cs_tx_usa cs_tx_usa is offline Offline
Newbie Poster

Re: How to compare floating point values

 
0
  #3
Mar 3rd, 2008
fLen1 is the length of the file that has been read. The file has floating point values between -1.0 and +1.0
“Remember: If you’re not experiencing failure, you’re not working hard enough!”
Jeffrey J. Mayer
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,839
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 298
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is online now Online
Roasting Maven

Re: How to compare floating point values

 
0
  #4
Mar 3rd, 2008
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:
  1. 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.

Niek
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 19
Reputation: cs_tx_usa is an unknown quantity at this point 
Solved Threads: 0
cs_tx_usa's Avatar
cs_tx_usa cs_tx_usa is offline Offline
Newbie Poster

Re: How to compare floating point values

 
0
  #5
Mar 4th, 2008
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.
“Remember: If you’re not experiencing failure, you’re not working hard enough!”
Jeffrey J. Mayer
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC