Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single precision (32 bit) floating point #3458

Open
2 tasks done
joelberkeley opened this issue Jan 2, 2025 · 1 comment
Open
2 tasks done

Single precision (32 bit) floating point #3458

joelberkeley opened this issue Jan 2, 2025 · 1 comment

Comments

@joelberkeley
Copy link
Contributor

joelberkeley commented Jan 2, 2025

  • I have read CONTRIBUTING.md.
  • I have checked that there is no existing PR/issue about my proposal.

Summary

I would like Idris to have a single precision 32-bit floating point primitive.

Motivation

My use case is numerical computing. Deep learning, in particular, uses this heavily.

The proposal

The main breaking change I foresee is that backends won't support it out of the box. @dunhamsteve even points out that JS might not be able to support it (I haven't looked). I know little about backends generally.

I also imagine this might introduce a bunch of resolution errors re floating point literals, unless we default to Double for backwards compatibility.

It would presumably be called Float, to match Double (and Idris1 Float?).

Do we want a floating-point interface for functions on floats (sin etc.), or do we overload. Overload seems practical, assuming we won't add any other precisions (what about complex?).

Examples

Trivially obvious, but anyway ...

pi : Float
pi = 3.141592625358979

Technical implementation

I assume the C implementation will just be float.

Idris code may just be a copy-paste for interfaces on Double.

Alternatives considered

Not introducing it.

Other alternatives require more insight into implementation.

Conclusion

I'm not aware of any language with fixed-width floating point that doesn't have this.

@joelberkeley joelberkeley changed the title Support single precision (32 bit) floating point Single precision (32 bit) floating point Jan 2, 2025
@buzden
Copy link
Contributor

buzden commented Jan 3, 2025

A feasible alternative can be to have a library with [external] datatype and FFI calls for primitive operations, literals support and standard interface implementations. Particular library is free to not to support all backends, so there will be no problem with js inability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants