查看浮点标准 IEEE754 精要的源代码
←
浮点标准 IEEE754 精要
跳转到:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您刚才请求的操作只有这个用户组中的用户才能使用:
用户
您可以查看并复制此页面的源代码:
=== 类型互转通用函数 === 与 float / double 类型互相转换的跨平台通用函数: import the file "[[ieeehalfprecision.c]]" into your project and use it like this : <source lang=cpp> #include "ieeehalfprecision.c" void test_fp16() { float myFloat = 1.245; uint16_t myfp16 = 0; float2halfp(&myfp16, &myFloat, 1); // convert 1 float to fp16 Serial.println("Testing the float16 function... "); Serial.print("Convert fp32=1.245 to fp16, HEX: "); Serial.println(myfp16, HEX); float myfp32 = 0; halfp2float(&myfp32, &myfp16, 1); // recover from 1 fp16 to float Serial.print("fp16 to float: "); Serial.println((double)myfp32, 3); } void setup() { Serial.setRouteLoc(1); Serial.begin(115200); } void loop() { __fp16 f1 = 0.232; Serial.println("Testing the float16, supported by gcc... "); Serial.print("sizeof(fp16): "); Serial.println(sizeof(f1)); Serial.print("f1 = "); Serial.println((double)f1, 4); // test the function test_fp16(); delay(5000); } </source> 输出: <source lang=bash> --------------------------------------------------- Testing the float16, supported by gcc... sizeof(fp16): 2 f1 = 0.2321 --------------------------------------------------- Testing the general function of float16... Convert fp32=13.245 to fp16, HEX: 4A9F fp16 to float: 13.242 --------------------------------------------------- ----- Test the [0, 1] ----- 0.0000000000 = 0x0 0x2 = 0.0000001192 0x3 = 0.0000001788 0x4 = 0.0000002384 0x80 = 0.0000076294 0x800 = 0.0001220703 0x2000 = 0.0078125000 0x2001 = 0.0078201294 0x2002 = 0.0078277588 0x3000 = 0.1250000000 0x3BFD = 0.9985351563 0x3BFE = 0.9990234375 0x3BFF = 0.9995117188 1.0000000000 = 0x3C00 ----- Test the [-1, 0] ----- 0x8002 = -0.0000001192 0x8003 = -0.0000001788 0x8004 = -0.0000002384 0x8080 = -0.0000076294 0x8800 = -0.0001220703 0xA000 = -0.0078125000 0xA001 = -0.0078201294 0xA002 = -0.0078277588 0xB000 = -0.1250000000 0xBBFD = -0.9985351563 0xBBFE = -0.9990234375 0xBBFF = -0.9995117188 ----- Test the [1, 2048] ----- 0x3C01 = 1.0009765625 0x3C02 = 1.0019531250 0x3CFD = 1.2470703125 0x3CFE = 1.2480468750 0x3CFF = 1.2490234375 3.6760001183 = 0x435A 3.6770000458 = 0x435B 3.6779999733 = 0x435B 3.5439999104 = 0x4317 3.5450000763 = 0x4317 3.5460000038 = 0x4318 0x3D00 = 1.2500000000 0x3E00 = 1.5000000000 0x4000 = 2.0000000000 0x4001 = 2.0019531250 0x4002 = 2.0039062500 0x5000 = 32.0000000000 0x5001 = 32.0312500000 0x5002 = 32.0625000000 32.1234016418 = 0x5004 32.2234001160 = 0x5007 32.2253990173 = 0x5007 0x6000 = 512.0000000000 0x6001 = 512.5000000000 0x6002 = 513.0000000000 0x67FE = 2046.0000000000 0x67FF = 2047.0000000000 2048.0000000000 = 0x6800 ----- Test the [2048, NaN] ----- 4096.0000000000 = 0x6C00 8192.0000000000 = 0x7000 16384.0000000000 = 0x7400 32768.0000000000 = 0x7800 65504.0000000000 = 0x7BFF 0x7BFD = 65440.0000000000 0x7BFE = 65472.0000000000 0x7BFF = 65504.0000000000 0x7C00 = inf 0x7C01 = nan 0x7D00 = nan 0x7E00 = nan 0x7F00 = nan 0x8000 = 0.0000000000 </source> 更多参考:https://www.mathworks.com/matlabcentral/fileexchange/23173-ieee-754r-half-precision-floating-point-converter <br>
返回到
浮点标准 IEEE754 精要
。
个人工具
登录
名字空间
页面
讨论
变换
查看
阅读
查看源代码
查看历史
操作
搜索
导航
首页
社区专页
新闻动态
最近更改
随机页面
帮助
工具箱
链入页面
相关更改
特殊页面