CS:APP上的一道题

RiderOnStorm 2006-08-22 03:09:00
Homework Problem 2.56:
Fill in the return value for the following procedure that tests whether its first argument is greater than or equal to its second. Assume the function f2u returns an unsigned 32-bit number having the same bit representation as its floating-point argument. You can assume that neither argument is NaN. The two flavors of zero: +0 and -0 are considered equal.

int float_ge(float x, float y)
{
unsigned ux = f2u(x);
unsigned uy = f2u(y);

/* Get the sign bits */
unsigned sx = ux >> 31;
unsigned sy = uy >> 31;

/* Give an expression using only ux, uy, sx, and sy */
return /* ... */ ;
}
...全文
319 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
bohlee 2006-08-24
  • 打赏
  • 举报
回复
mark
RiderOnStorm 2006-08-22
  • 打赏
  • 举报
回复
To blue_zyb():

谢谢你回复。答案应该不对,没有考虑x=-0(100...0),y=+0(000...0)的情况。

另外,组合一些条件判断肯定能够解答这道题目,但我总觉得既然题目要你用一个表达式搞定,一定有更简洁的解法。
blue_zyb 2006-08-22
  • 打赏
  • 举报
回复
return (sx < sy) || (sx == 0) && (ux >= uy) || (sx == 1) && (ux <= uy);

不知道对不对?:)
muroachanf 2006-08-22
  • 打赏
  • 举报
回复
回家再看

64,637

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧