Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The solution to 2.84 seems to have a problem #1

Closed
HITKehaoChen opened this issue Sep 22, 2017 · 10 comments
Closed

The solution to 2.84 seems to have a problem #1

HITKehaoChen opened this issue Sep 22, 2017 · 10 comments

Comments

@HITKehaoChen
Copy link

I think you should not simply judge ux uy by comparing sx==sy. I think maybe the link is a proper answer.
https://github.com/mofaph/csapp/blob/master/exercise/ex2-83.c

@DreamAndDead
Copy link
Owner

I think we get the same goal with different expressions.

@zagortenay333
Copy link

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

@DreamAndDead
Copy link
Owner

@zagortenay333 did you mean +0 and -0?

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

@zagortenay333
Copy link

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

@DreamAndDead DreamAndDead reopened this Apr 24, 2018
@DreamAndDead
Copy link
Owner

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

@zagortenay333
Copy link

    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   */

@DreamAndDead
Copy link
Owner

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

@1036-ce
Copy link

1036-ce commented Apr 27, 2021

Thank you!!

@sci-42ver
Copy link

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

@paradox181
Copy link

paradox181 commented Mar 13, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants