aboutsummaryrefslogtreecommitdiff
path: root/std/math/complex/ldexp.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/complex/ldexp.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/complex/ldexp.zig')
-rw-r--r--std/math/complex/ldexp.zig13
1 files changed, 7 insertions, 6 deletions
diff --git a/std/math/complex/ldexp.zig b/std/math/complex/ldexp.zig
index a56c2ef2eb..e919ef6bec 100644
--- a/std/math/complex/ldexp.zig
+++ b/std/math/complex/ldexp.zig
@@ -4,7 +4,7 @@ const math = std.math;
const cmath = math.complex;
const Complex = cmath.Complex;
-pub fn ldexp_cexp(z: var, expt: i32) Complex(@typeOf(z.re)) {
+pub fn ldexp_cexp(z: var, expt: i32) @typeOf(z) {
const T = @typeOf(z.re);
return switch (T) {
@@ -20,11 +20,12 @@ fn frexp_exp32(x: f32, expt: *i32) f32 {
const exp_x = math.exp(x - kln2);
const hx = @bitCast(u32, exp_x);
- expt.* = i32(hx >> 23) - (0x7f + 127) + k;
+ // TODO zig should allow this cast implicitly because it should know the value is in range
+ expt.* = @intCast(i32, hx >> 23) - (0x7f + 127) + k;
return @bitCast(f32, (hx & 0x7fffff) | ((0x7f + 127) << 23));
}
-fn ldexp_cexp32(z: *const Complex(f32), expt: i32) Complex(f32) {
+fn ldexp_cexp32(z: Complex(f32), expt: i32) Complex(f32) {
var ex_expt: i32 = undefined;
const exp_x = frexp_exp32(z.re, &ex_expt);
const exptf = expt + ex_expt;
@@ -45,16 +46,16 @@ fn frexp_exp64(x: f64, expt: *i32) f64 {
const exp_x = math.exp(x - kln2);
const fx = @bitCast(u64, x);
- const hx = u32(fx >> 32);
+ const hx = @intCast(u32, fx >> 32);
const lx = @truncate(u32, fx);
- expt.* = i32(hx >> 20) - (0x3ff + 1023) + k;
+ expt.* = @intCast(i32, hx >> 20) - (0x3ff + 1023) + k;
const high_word = (hx & 0xfffff) | ((0x3ff + 1023) << 20);
return @bitCast(f64, (u64(high_word) << 32) | lx);
}
-fn ldexp_cexp64(z: *const Complex(f64), expt: i32) Complex(f64) {
+fn ldexp_cexp64(z: Complex(f64), expt: i32) Complex(f64) {
var ex_expt: i32 = undefined;
const exp_x = frexp_exp64(z.re, &ex_expt);
const exptf = i64(expt + ex_expt);