[racket] Typed Racket Performance Optimization
As Neil said, `fllog' is guaranteed to return floats.
If you want to know for which input types `log' has a return type of
`Float', you can use `:query-result-type' at the TR REPL.
-> (:query-result-type log Float)
(case-> (Nonnegative-Flonum -> Float) (Float-Zero -> Negative-Float))
If you can't restrict the input type, the solution you mention (adding a
runtime assertion) is perfectly fine, but does involve a check at runtime.
Vincent
At Wed, 9 May 2012 23:52:42 -0400,
Ray Racine wrote:
>
> [1 <multipart/alternative (7bit)>]
> [1.1 <text/plain; ISO-8859-1 (7bit)>]
> The Typed Racket Performance button in DrRacket informs me that (log v)
> returns a Complex type, despite all its arguments being reals and that if I
> do not want or expect a complex number as results, I mam restrict the type
> of the arguments. How does one do that?
>
> #lang typed/racket/base
>
> (: real-log (Float -> Float))
> (define (real-log v)
> (assert (log v) flonum?))
> [1.2 <text/html; ISO-8859-1 (quoted-printable)>]
>
> [2 <text/plain; us-ascii (7bit)>]
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users