Skip to content

a f16 ieee754-2008 implement inspired by rust half crate. Including the mutual conversion between F32 and F16, and the comparison of F16.

Notifications You must be signed in to change notification settings

KenForever1/F16cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

简介

F16.hpp实现了IEEE754-2008标准的Float16类型表示, 以及实现了Float32和Float16类型的互相转换。F16类型的直接比较大小方法。

主要函数:

  • f32_to_f16_fallback:将F16类型转换成F32类型
  • f16_to_f32_fallback:将F32类型转换成F16类型
  • 重载了比较大小的operator函数

F16cpp inspired by rust half crate.

使用

#include "F16.hpp"

int main(){
    F16 a;
    a.from_f32(0);

    F16 b;
    b.from_f32(-0);
    std::cout << "a = " << a.to_f32() << "\n";
    std::cout << "b = " << b.to_f32() << "\n";

    std::cout << "a == b: " << (a == b) << "\n";
    std::cout << "a < b: " << (a < b) << "\n";
    std::cout << "a > b: " << (a > b) << "\n";
}

About

a f16 ieee754-2008 implement inspired by rust half crate. Including the mutual conversion between F32 and F16, and the comparison of F16.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published