Giter VIP home page Giter VIP logo

float16's Introduction

Half Float IEEE Library for C and Z80

This is a library that implements IEEE 16 bit half float in

  • C - general purpose code
  • Z80 - assembly as useful high performance floating point library for 8bit systems

It supports:

  • Basic operations "+", "-", "*", "/"
  • Conversion to/from integer
  • Comparison operations

It uses IEEE 754 format. It supports full range of values including +/- inf, nan and subnormal values. All operations work as expected with the respect of inf/nan values

Only simplest truncation rounding policy implemented, no round to nearest ties to evens provided.

What is expected in future:

  • math functions: log/exp, trigonometry etc,
  • formatting/parsing functions

Z80 notes

  • All functions are reentrant and relay on alternative set of registers AF', HL', DE', BC', so if your interrupt routines use shadow registers for fast context switching you can't use this library.
  • Some functions is IX for frame pointer, IY is not modified.
  • Each functions come in two variants the z88dk C calling format and using registers, for example _f16_add with parameters passed over stack and _f6_add_hl_de that the parameters passed via hl and de, and result returned in hl

float16's People

Contributors

artyom-beilis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

float16's Issues

LSB rounding issue

f16_add(0x0001, 0x0801) => 0x0801
gcc 12.2 same calculations in _Float16 shows 0x0802

Create a type instead of using short

If nothing else it would probably be more appropriate to use int16_t instead of short. But even that should only be used internally IMHO. I think you should create your own type so it's clearer to people reading code using the API what is going on.

A simple typedef to int16_t would be an improvement, but I think a better solution would be something like typedef struct { int16_t val; } foo_float16; since it would trigger an error if people try to use arithmetic operators (+, -, *, /, etc.).

That said, some compilers have at least some support for 16-bit floats. Clang 6+ and GCC 4.5+ for starters. It would be nice if you could take advantage of that where available.

I'd also suggest you be careful about the name. float16_t is already taken by NEON, for example. Putting everything in a namespace would be an easy solution, but unfortunately calling the library "float16" is somewhat limiting there. FWIW, I probably would have been tempted to use something falcon-themed as a joke about the F-16 airplane. f16_t, maybe?

Conversion to/from float

It would be nice to be able to convert to/from standard floats. Generically if possible, but at least if the system is using IEEE 754 (__STDC_IEC_559__ should be defined, though TBH I wouldn't be surprised if an MSVC exception is necessary).

FWIW, I'm considering this as a way to implement the float16_t stuff in NEON portably in SIMDe. I'm going to open a couple more issues, I just wanted you to understand the perspective I'm looking at it from since you seem to be focused on retrocomputing and so probably have different things in mind. If you're not interested in supporting my use case that's fine; please feel free to just close the issues if that's the case.

Expose IS_INF and IS_NAN in API

These are useful, please expose them.

Since it would be better not to leak implementation details, I'd suggest that instead of macros you use f16_isnan and f16_isinf functions to match the standard C functions. It might also be nice to have f16_fpclassify and f16_isnormal too.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.