Giter Site home page Giter Site logo

Comments (10)

DreamAndDead avatar DreamAndDead commented on May 24, 2024

I think we get the same goal with different expressions.

from csapp-3e-solutions.

zagortenay333 avatar zagortenay333 commented on May 24, 2024

This solution doesn't handle zeros. x = 000..00 and y = 100..00

from csapp-3e-solutions.

DreamAndDead avatar DreamAndDead commented on May 24, 2024

@zagortenay333 did you mean +0 and -0?

This function named float_le, less or equal, so float_le(+0, -0) should return true here.

from csapp-3e-solutions.

zagortenay333 avatar zagortenay333 commented on May 24, 2024

Yes, but it won't return true when x=+0 and y=-0 since sx != sy and sx > sy is false.

from csapp-3e-solutions.

DreamAndDead avatar DreamAndDead commented on May 24, 2024

Yes, you are right. Any elegant way to solve this?

from csapp-3e-solutions.

zagortenay333 avatar zagortenay333 commented on May 24, 2024
    return
        !(ux<<1 || uy<<1) ||          /* both zero         */
        (sx > sy) ||                  /* x < 0 and y >= 0  */
        (!sx && !sy && ux <= uy) ||   /* x >= 0 and y >= 0 */
        (sx && sx && ux >= uy);       /* x < 0 and y < 0   */

from csapp-3e-solutions.

DreamAndDead avatar DreamAndDead commented on May 24, 2024

thanks @LittleCoke @zagortenay333 , how do you think 9d75393

from csapp-3e-solutions.

1036-ce avatar 1036-ce commented on May 24, 2024

Thank you!!

from csapp-3e-solutions.

sci-42ver avatar sci-42ver commented on May 24, 2024

maybe need use

assert(float_le(-0.0, +0.0));
assert(float_le(+0.0, -0.0));

to generate negative zero known from this.

maybe also can use return sx == sy ? (sx == 0 ? ux <= uy : ux >= uy) : sx > sy ? sx > sy : ux+uy==ux-uy && ux+uy==uy-ux; to test which is inspired by above https://github.com/mofaph/csapp/blob/master/exercise/ex2-83.c

from csapp-3e-solutions.

paradox181 avatar paradox181 commented on May 24, 2024

from csapp-3e-solutions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.