• Lucid Dreaming - Dream Views




    Results 1 to 13 of 13

    Thread: Crash my code

    Threaded View

    1. #11
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Quote Originally Posted by tommo View Post
      How can they if it is an impossible/illogical equation?
      They go into an "undefined" state. "undefined" is in quotes because it's mathematically undefined, but completely defined in code. You can not equate math undefined and computer undefined.

      1/3 is not defined in computer terms.

      Quote Originally Posted by IAmCoder View Post
      Code:
      if (NaN) {return false;}
      No, that will always go into the block.

      NaN is defined to be created by:
      Any mathematical operation with any of the parameters being NaN
      0/0
      +-inf/ +-inf
      +-inf * 0
      inf + -inf
      powr(0, 0)
      powr(1, inf)
      powr(inf, 0)
      sqtr(x) where x < 0
      log(x) where x < 0
      sin-1(x) where x < -1 or x > 1
      cos-1(x) where x < -1 or x > 1

      Any NaN is not equals to itself. A lot of newbie coders will see something like this in code
      Code:
      if (var != var) { /* do something */ }
      and remove it because they think it is an impossible case, and it's not. To get really detailed, there is actually two NaN versions.

      And actually 1/0 does not go into the NaN state, it goes into the inf state.
      Last edited by ninja9578; 08-02-2011 at 03:39 AM.

    Similar Threads

    1. Crack this code
      By Tyler in forum Senseless Banter
      Replies: 12
      Last Post: 07-31-2010, 04:24 PM
    2. Security code!?!?
      By Noogah in forum The Lounge
      Replies: 4
      Last Post: 10-30-2009, 03:59 AM
    3. Want to QA some C++ code?
      By ninja9578 in forum Tech Talk
      Replies: 15
      Last Post: 08-11-2009, 01:11 AM
    4. Decipher the code!
      By Original Poster in forum Senseless Banter
      Replies: 20
      Last Post: 11-12-2007, 02:30 AM

    Bookmarks

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •