Answers.Body: <p>I don't believe that a constant or macro is available in NXC for positive infinity. C99 defines INFINITY in math.h, but the <a href="http://bricxcc.sourceforge.net/nbc/nxcdoc/nxcapi/group__cmath_a_p_i.html" rel="nofollow">math module in NXC</a> does not appear to include this.</p>
  
  <p>NXC uses IEEE 754 floating point, so something like this should give you the raw value of infinity cast to a float:</p>
  
  <pre><code>int raw_infinity = 0x7f800000;
  const float INFINITY = *(float*)&amp;raw_infinity;
  </code></pre>
  
  <p>I don't have a way to test this currently, and I'm not sure how the underlying firmware and hardware handle special floating point values, so this may or may not actually meet your needs.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-25T10:14:56.607Z
Answers.Text: Thank you! Seems to be working- at least compiles, except for the "(float)&". Are you sure, that it is possible to cast type like this? I think, it just does it automatically: <br/> `int raw_infinity = 0x7f800000; const float INFINITY = raw_infinity;` or just `const float INFINITY =  0x7f800000`
Answers.UserDisplayName: elle
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-25T13:21:34.360Z
Answers.Text: At least in standard C, you have to do the cast in the way I did in my answer. C will treat the hex value as an `int` and cast that value to a float. You need the actual binary representation to be used as a float directly without casting it through an `int` first.
Answers.UserDisplayName: jncraton
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-21T23:37:01.117Z
Answers.LastActivityDate: 2016-05-21T23:37:01.117Z
Answers.UserDisplayName: jncraton
Body: <p>Is there anything like Java's <code>Float.POSITIVE_INFINITY</code> in NXC?
  How else can one represent the positive infinity in NXC?</p>
  
Tags: <nxc>
Title: How to represent infinity in NXC?
UserDisplayName: elle
ThreadText: # How to represent infinity in NXC?
  
  (Asked by: username_0 on 2016-05-20)
  
  Is there anything like Java's `Float.POSITIVE_INFINITY` in NXC?
  How else can one represent the positive infinity in NXC?
  
  **Tags:** nxc
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-05-21. Score: 1 | Accepted answer
  
  I don't believe that a constant or macro is available in NXC for positive infinity. C99 defines INFINITY in math.h, but the math module in NXC does not appear to include this.
  NXC uses IEEE 754 floating point, so something like this should give you the raw value of infinity cast to a float:
  int raw_infinity = 0x7f800000;
  const float INFINITY = *(float*)&raw_infinity;
  
  I don't have a way to test this currently, and I'm not sure how the underlying firmware and hardware handle special floating point values, so this may or may not actually meet your needs.
  
  > **Comments:**
  > **username_0**: Thank you! Seems to be working- at least compiles, except for the "(float)&". Are you sure, that it is possible to cast type like this? I think, it just does it automatically: <br/> `int raw_infinity = 0x7f800000; const float INFINITY = raw_infinity;` or just `const float INFINITY =  0x7f800000`  
  > **username_1**: At least in standard C, you have to do the cast in the way I did in my answer. C will treat the hex value as an `int` and cast that value to a float. You need the actual binary representation to be used as a float directly without casting it through an `int` first.  
  
  ---
  
  