sykopomp/squirl — Issue #2: Type-error in angle->vec when passed a single-float
Author: jacius
Created: 2012-02-20 20:36:47+00:00
State: open

On SBCL (1.0.55), when passing a single-float to angle->vec, e.g. `(squirl:angle->vec 0.5)`, I get the following error:

debugger invoked on a TYPE-ERROR:
The value #C(0.87758255 0.47942555) is not of type (COMPLEX DOUBLE-FLOAT).

The issue seems to be that cis returns single-float results unless it's given a double-float input, so the return value of angle->vec did not match the declaimed return type. To solve this, I patched angle->vec to explicitly coerce its results to a vec:

```diff
diff --git a/src/vec.lisp b/src/vec.lisp
index b58552a..f855c30 100644
--- a/src/vec.lisp
+++ b/src/vec.lisp
@@ -53,7 +53,7 @@ WITH-VEC binds NAME.x and NAME.y in the same manner as `with-a
(inline angle->vec))
(defun angle->vec (angle)
"Convert radians to a normalized vector"
- (cis angle))
+ (coerce (cis angle) 'vec))

(declaim (ftype (function (vec) real) vec->angle)
(inline vec->angle))
```

An alternative "fix" with no performance hit would be to just state in the docs that the input must be a double-float, and maybe change the declaimed input type.