# 李锦俊(mybios)的blog

C++博客 :: 首页 :: 联系 :: 聚合  :: 管理

### 公告

QQ:30743734
EMain:mybios@qq.com

•

• 积分 - 360243
• 排名 - 66

### 评论排行榜

```

/* 来至 Quake 3 的源码 */

float
CarmSqrt(float x){union{int intPart;
float floatPart;
} convertor;
union{int intPart;
float floatPart;
} convertor2;
convertor.floatPart = x;
convertor2.floatPart = x;
convertor.intPart = 0x1FBCF800 + (convertor.intPart >> 1);
convertor2.intPart = 0x5f3759df - (convertor2.intPart >> 1);
return0.5f*(convertor.floatPart + (x * convertor2.floatPart));
}```

```union luai_Cast {double l_d; long l_l; };
#define lua_number2int(i,d) \{volatileunion luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; }```

RGB565 的 alpha 混合
```unsignedshort alpha_blender(unsignedint x,unsignedint y,unsignedint alpha){
x = (x | (x<<16)) & 0x7E0F81F;
y = (y | (y<<16)) & 0x7E0F81F;
unsignedint result = ((x - y) * alpha / 32 + y) & 0x7E0F81F;
return(unsignedshort)((result&0xFFFF) | (result>>16));
}```

```unsignedlong hash(constchar *name,size_t len){unsignedlong h=(unsignedlong)len;
size_t step = (len>>5)+1;
for(size_t i=len; i>=step; i-=step)
h = h ^ ((h<<5)+(h>>2)+(unsignedlong)name[i-1]);
return h;
}```

UTF8 到 UTF16 的转换(单个字符)
```int UTF8toUTF16(int c){signedchar *t=(signedchar*)&c;
int ret=*t &(0x0f | ((*t>>1) &0x1f) | ~(*t>>7));
int i;
assert ((*t & 0xc0) != 0x80);
for(i=1;i<3;i++){if((t[i] & 0xc0)!=0x80){break;
}
ret=ret<<6 | (t[i] & 0x3f);
}return ret;
}```

posted on 2006-11-18 15:17 李锦俊(mybios) 阅读(2697) 评论(4)  编辑 收藏 引用 所属分类: C++

### Feedback

# re: 【转贴】一些高效代码片段 2010-08-02 07:15 SheliaBates
Make your own life time more simple take the <a href="http://bestfinance-blog.com/topics/personal-loans">personal loans</a> and all you require.   回复  更多评论

# re: 【转贴】一些高效代码片段 2010-08-11 17:59 buy research paper
I was so fortunate to find your page exactly one day before the deadline of my buy research paper and buy research paper. I know that you are a well-recognized and reliable source on the Internet.  回复  更多评论

# re: 【转贴】一些高效代码片段 2010-08-12 06:33 custom essays
Your outcome is hot! Therefore students not have to compose the custom essays and research paper by their efforts, they could take your help.   回复  更多评论