Go to Post The teams that know how to build good robots are the same teams that know how to build good teams, and they engage the students every step of the way. - Chris is me [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 11-02-2011, 09:17
jwakeman jwakeman is offline
Registered User
FRC #0063 (Red Barons)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: 16510
Posts: 182
jwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nice
Testing for infinity

Hi,

I would like to test if the value returned in a double is infinity. I tried comparing if the bytes of the double were equal to 0x7F00000000000000 and I tried if(atof("infinity") == doubleVal) but the first always returned false and the second always returned true. I see a function infinity( ) in mathALib that looked like it might be helpful but I'm not sure how to include that lib. I can compile using that function but get a link error once on the cRIO. So really two questions here:

1. How to link with a lib like mathALib?
2. A nice way to check for infinity (and maybe NaN while your at it)?

Thanks!
Reply With Quote
  #2   Spotlight this post!  
Unread 11-02-2011, 10:42
davidalln's Avatar
davidalln davidalln is offline
World's Worst Coder
AKA: David Allen
FRC #2415 (The Westminster Wiredcats)
Team Role: Programmer
 
Join Date: Mar 2009
Rookie Year: 2008
Location: Atlanta, GA
Posts: 108
davidalln is on a distinguished road
Send a message via AIM to davidalln
Re: Testing for infinity

I don't have an answer to your question, but I'm curious how infinity/NaN somehow is useful in your program

Are you dividing by zero somewhere?
__________________
SANTOSH ANDREW DECKER RICK WYNNIE SEAN DEREK MATT
(alamo (semis), p'tree (CHAMPS!), nc (CHAMPS!), newton (quarters))


Best four years of my life. Thanks to everyone who made it happen.
Reply With Quote
  #3   Spotlight this post!  
Unread 11-02-2011, 12:54
jwakeman jwakeman is offline
Registered User
FRC #0063 (Red Barons)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: 16510
Posts: 182
jwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nice
Re: Testing for infinity

I am using a gear tooth sensor and am using the GearTooth class. I call GetPeriod() from the Counter superclass to calculate a rate. At very slow speeds it will sometimes return Inf because no teeth have passed by since I last called GetPeriod I guess. I want to detect Inf and play some games with the rate value I am returning.
Reply With Quote
  #4   Spotlight this post!  
Unread 11-02-2011, 12:59
basicxman basicxman is offline
Emily Horsman
FRC #2200 (MMRambotics)
Team Role: Programmer
 
Join Date: Oct 2007
Rookie Year: 2007
Location: Burlington, Ontario
Posts: 971
basicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant future
Send a message via AIM to basicxman Send a message via MSN to basicxman Send a message via Yahoo to basicxman
Re: Testing for infinity

Quote:
Originally Posted by jwakeman View Post
I am using a gear tooth sensor and am using the GearTooth class. I call GetPeriod() from the Counter superclass to calculate a rate. At very slow speeds it will sometimes return Inf because no teeth have passed by since I last called GetPeriod I guess. I want to detect Inf and play some games with the rate value I am returning.
I do believe there's a bug in the FPGA with Encoder and GearTooth's GetRate/GetPeriod functions. Could be wrong...
Reply With Quote
  #5   Spotlight this post!  
Unread 11-02-2011, 13:44
jwakeman jwakeman is offline
Registered User
FRC #0063 (Red Barons)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: 16510
Posts: 182
jwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nice
Re: Testing for infinity

I don't think its a bug. I asked him how much time between the last two pulses you saw? He replied, haven't seen any pulses.
Reply With Quote
  #6   Spotlight this post!  
Unread 11-02-2011, 14:24
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,590
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Testing for infinity

In labview, at least, you can configure the timer so you can define what the time period is where if no pulses are seen, it is considered stopped. You can also get a stopped boolean value. I expect there is something similar in C++ if you dig around in the library. You could then use the stopped value instead of testing for infinity.
Reply With Quote
  #7   Spotlight this post!  
Unread 11-02-2011, 14:54
jwakeman jwakeman is offline
Registered User
FRC #0063 (Red Barons)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: 16510
Posts: 182
jwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nice
Re: Testing for infinity

Ah good point, there are two function in Counter SetMaxPeriod and SetUpdateWhenEmpty which are there to configure this sort of behavior. Those are likely the best solution to my problem. Still if anyone can answer the two original questions I would appreciate it.
Reply With Quote
  #8   Spotlight this post!  
Unread 12-02-2011, 23:03
mandrews281 mandrews281 is offline
Registered User
FRC #0281
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2006
Location: Greenville SC
Posts: 83
mandrews281 is a splendid one to beholdmandrews281 is a splendid one to beholdmandrews281 is a splendid one to beholdmandrews281 is a splendid one to beholdmandrews281 is a splendid one to beholdmandrews281 is a splendid one to beholdmandrews281 is a splendid one to behold
Re: Testing for infinity

I don't have WindRiver anywhere near me at the moment, but assuming math.h exists, there are functions like isinf(x) and/or the constants FP_INFINITE and FP_NAN in the floating point standards. So you might be able to write

#include <math.h>

if (isinf(1.0/0.0)) {
do something
}

On most development systems, including math.h that means you also need to link against the math library (-lm). I don't know if WindRiver would do that automatically.
__________________
Michael Andrews
Team #281 Programming Mentor
Reply With Quote
  #9   Spotlight this post!  
Unread 13-02-2011, 08:41
jwakeman jwakeman is offline
Registered User
FRC #0063 (Red Barons)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: 16510
Posts: 182
jwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nice
Re: Testing for infinity

Linking with the math lib was one of my issues. I tried -lm from my linux experience but the compiler didn't recognize it.
Reply With Quote
  #10   Spotlight this post!  
Unread 13-02-2011, 15:21
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: Testing for infinity

It's a single mode OS... if you have a header that defines the symbols and you are not trying to statically link the library in, then you just need to load your library. The symbols will be looked up at runtime.

-Joe
Reply With Quote
  #11   Spotlight this post!  
Unread 14-02-2011, 23:11
tmiddlet tmiddlet is offline
Registered User
FRC #2083
 
Join Date: Feb 2011
Location: Colorado
Posts: 1
tmiddlet is an unknown quantity at this point
Re: Testing for infinity

We were doing this exact same thing!
I know how we tested for NaN, but we didn't use infinity.
If a number is equal to NaN, it is not equal to itself

double nan = 1/0*8; //NaN
if (nan != nan) {
// nan is equal to NaN
}
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 13:32.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi