How to type hint a float?

64 Views Asked by At

I want to ensure I'm using unboxed and unreflected arithmetic on arrays of floats, but I can't get it to compile.

How can I type hint a float in a function like this?

(defn ff2a
  ^"[F" ; Return type hint for a float array
  [^float f1 ^float f2] ; Argument type hints
  (float-array [f1 f2]))

I get this error when I try to load it into the REPL:

Syntax error (IllegalArgumentException) compiling fn* [...] Only long and double primitives are supported

1

There are 1 best solutions below

0
Eugene Pakhomov On

You can't. The error is quite clear. Even this fails:

user=> (defn f [^float x])
Syntax error (IllegalArgumentException) compiling fn* at (REPL:1:1).
Only long and double primitives are supported

You can still use unboxed doubles. If that doesn't work for you, it might be better to implement this particular part in Java.