Thread: Parenthesis in convoluted if statements [FIXED]

  1. #1
    Registered User
    Join Date
    Nov 2020
    Posts
    2

    Parenthesis in convoluted if statements [FIXED]

    Hi,
    I seem to have issues with how ==, && and || are evaluated. Particularly in the following:
    Code:
    uint8_t  16float_equals(tfl16_t a, tfl16_t b) {
        if ((((a^b)==0)) || ((a&0x3ff==0) && (b&0x3ff==0))) {// (((a<<17)|(b<<17))==0)) { // (((a<<1)|(b<<1))==0)) {
            return 1; 
        } else {
            return 0;
        }
    }
    



    The second part checks for 0 and their variations in a custom 16 float in bit representation ie:
    0b1000000000000000 = 0
    0b0000010000000000 = 0
    etc..

    but it doesnt work for the following:
    32768 and 0 where it says they are not the same


    Last edited by TomHaddock; 11-24-2020 at 05:07 PM.

  2. #2
    Registered User
    Join Date
    Nov 2020
    Posts
    2
    It has now been fixed, I think I get the order more now

    Code:
    uint8_t
    Code:
      tfl_equals(tfl16_t a, tfl16_t b) {
        if ((((a^b)==0)) || (((a&0x3ff)==0) && ((b&0x3ff)==0))) {// (((a<<17)|(b<<17))==0)) { // (((a<<1)|(b<<1))==0)) {
            return 1; 
        } else {
            return 0;
        }
    }

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,420
    Your choice of font colours is abominable.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    311
    "without goto we would be wtf'd"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Parenthesis error in debug
    By Creandum in forum C Programming
    Replies: 6
    Last Post: 01-15-2013, 04:05 PM
  2. Parenthesis operator overload
    By jack_carver in forum C++ Programming
    Replies: 2
    Last Post: 04-13-2011, 09:25 AM
  3. Replies: 3
    Last Post: 11-11-2003, 03:44 AM
  4. find where the missing parenthesis are?
    By the Wookie in forum C++ Programming
    Replies: 5
    Last Post: 03-21-2003, 09:57 PM
  5. two arguments own parenthesis?.!
    By Shadow12345 in forum C++ Programming
    Replies: 3
    Last Post: 05-12-2002, 08:51 PM

Tags for this Thread