设为首页 加入收藏

TOP

datalab (原发布 csdn 2018年09月21日 20:42:54)(二)
2019-09-06 00:27:13 】 浏览:57
Tags:datalab 发布 csdn 2018年 09月 21日 20:42:54
- return floor(log base 2 of x), where x > 0 * Example: ilog2(16) = 4 * Legal ops: ! ~ & ^ | + << >> * Max ops: 90 * Rating: 4 */ int ilog2(int x) { return 2; } /* * float_neg - Return bit-level equivalent of expression -f for * floating point argument f. * Both the argument and result are passed as unsigned int's, but * they are to be interpreted as the bit-level representations of * single-precision floating point values. * When argument is NaN, return argument. * Legal ops: Any integer/unsigned operations incl. ||, &&. also if, while * Max ops: 10 * Rating: 2 */ unsigned float_neg(unsigned uf) { int offsetValue = 0x1; int offsetIndex = 0; int andValue = 0; int signValue; while (offsetIndex < 31) { signValue = (uf & offsetValue) >> offsetIndex; if (offsetIndex < 23) { andValue = andValue | signValue; } else { andValue = andValue & signValue; } offsetIndex += 1; offsetValue <<= 1; } if (andValue) { return uf;//NaN } return uf ^ offsetValue; } /* * float_i2f - Return bit-level equivalent of expression (float) x * Result is returned as unsigned int, but * it is to be interpreted as the bit-level representation of a * single-precision floating point values. * Legal ops: Any integer/unsigned operations incl. ||, &&. also if, while * Max ops: 30 * Rating: 4 */ unsigned float_i2f(int x) { return 2; } /* * float_twice - Return bit-level equivalent of expression 2*f for * floating point argument f. * Both the argument and result are passed as unsigned int's, but * they are to be interpreted as the bit-level representation of * single-precision floating point values. * When argument is NaN, return argument * Legal ops: Any integer/unsigned operations incl. ||, &&. also if, while * Max ops: 30 * Rating: 4 */ unsigned float_twice(unsigned uf) { int signIndex = 31; int expIndex = 23; int offsetValue = 0x1; int offsetSign = offsetValue << signIndex; int andValue = 1; int orValue = 0; int signValue; int offsetIndex = expIndex; while (offsetIndex < signIndex) { signValue = (uf & (offsetValue << offsetIndex)) >> offsetIndex; andValue = andValue & signValue; orValue = orValue | signValue; offsetIndex += 1; } if (andValue == 1)//exp==255 { return uf; } else if (orValue == 0)//非规格化 { signValue = !!(uf & offsetSign); uf <<= 1; if (signValue == 0) { return uf & (~offsetSign); } return uf | offsetSign; } else { signValue = ((uf >> expIndex) + 1) << expIndex; offsetIndex = expIndex; while (offsetIndex < signIndex) { uf &= ~(offsetValue << offsetIndex); offsetIndex += 1; } return uf | signValue; } }

在这里插入图片描述

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇性能优化概述 下一篇Ubuntu系统降内核

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目