aboutsummaryrefslogtreecommitdiff
path: root/std/math/log.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-06-17 02:57:07 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-06-17 02:57:07 -0400
commit79120612267f55901029dd57290ee90c0a3ec987 (patch)
tree60a30197720ccd8152db8112d0c271a595e725cf /std/math/log.zig
parent06a26f0965deff3d752da3d448b34872010d80f3 (diff)
downloadzig-79120612267f55901029dd57290ee90c0a3ec987.tar.gz
zig-79120612267f55901029dd57290ee90c0a3ec987.zip
remove integer and float casting syntax
* add `@intCast` * add `@floatCast` * add `@floatToInt` * add `@intToFloat` See #1061
Diffstat (limited to 'std/math/log.zig')
-rw-r--r--std/math/log.zig11
1 files changed, 6 insertions, 5 deletions
diff --git a/std/math/log.zig b/std/math/log.zig
index 2c876081d8..20b6d055e8 100644
--- a/std/math/log.zig
+++ b/std/math/log.zig
@@ -13,22 +13,23 @@ pub fn log(comptime T: type, base: T, x: T) T {
return math.ln(x);
}
+ const float_base = math.lossyCast(f64, base);
switch (@typeId(T)) {
TypeId.ComptimeFloat => {
- return @typeOf(1.0)(math.ln(f64(x)) / math.ln(f64(base)));
+ return @typeOf(1.0)(math.ln(f64(x)) / math.ln(float_base));
},
TypeId.ComptimeInt => {
- return @typeOf(1)(math.floor(math.ln(f64(x)) / math.ln(f64(base))));
+ return @typeOf(1)(math.floor(math.ln(f64(x)) / math.ln(float_base)));
},
builtin.TypeId.Int => {
// TODO implement integer log without using float math
- return T(math.floor(math.ln(f64(x)) / math.ln(f64(base))));
+ return @floatToInt(T, math.floor(math.ln(@intToFloat(f64, x)) / math.ln(float_base)));
},
builtin.TypeId.Float => {
switch (T) {
- f32 => return f32(math.ln(f64(x)) / math.ln(f64(base))),
- f64 => return math.ln(x) / math.ln(f64(base)),
+ f32 => return @floatCast(f32, math.ln(f64(x)) / math.ln(float_base)),
+ f64 => return math.ln(x) / math.ln(float_base),
else => @compileError("log not implemented for " ++ @typeName(T)),
}
},