# Sema: error on ambiguous coercion of comptime float and ints · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/07f64a2e13ab80acffba7f7bdd5d7c58df7893c0)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 07f64a2e13ab80acffba7f7bdd5d7c58df7893c0

Requested commit: 07f64a2e13ab80acffba7f7bdd5d7c58df7893c0

Commit: 07f64a2e13ab80acffba7f7bdd5d7c58df7893c0

Tree: e35bf8eea3846afca0a3d42f1436b1759f39c60a

Author: Martin Hafskjold Thoresen

Committer: Andrew Kelley

## Message

````
Sema: error on ambiguous coercion of comptime float and ints

The following, from the documentation as of the time of writing, illustrates
the problem:

```zig
// Compile time coercion of float to int
test "implicit cast to comptime_int" {
    var f: f32 = 54.0 / 5;
    _ = f;
}
```

It is not clear how to unify the types of 54.0 and 5 to perform the
division. We can either

 - cast 54.0 to comptime_int resulting in @as(comptime_int, 10), which is
   casted to @as(f32, 10), or
 - cast 5 to comptime_float resulting in @as(comptime_float, 10.8), which
   is casted to @as(f32, 10.8)

Since the two resulting values are different, a compiler error is appropriate.

If we know that casting to either type will result in the same value we
don't need to error.  For instance, 10.0 / 2 is okay, as is 10 / 2.0.

Fixes: #12364

````

## Parents

- [070282a96ec23fb41041843d5753608ec5090f8b](https://git.cafe/gitcafe/zig/commit/070282a96ec23fb41041843d5753608ec5090f8b?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/07f64a2e13ab80acffba7f7bdd5d7c58df7893c0?format=markdown)
