aboutsummaryrefslogtreecommitdiff
path: root/lib/std/math.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-01-10 19:04:10 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-01-10 19:04:10 -0700
commit169810b20fb6ce036ed0ff2990f06751aa11e623 (patch)
tree3609306627c17f83745046cccbde57760088eb4d /lib/std/math.zig
parent0f32de77c91a3761a4434d1790018b5c2c6fa099 (diff)
downloadzig-169810b20fb6ce036ed0ff2990f06751aa11e623.tar.gz
zig-169810b20fb6ce036ed0ff2990f06751aa11e623.zip
zig fmt
Diffstat (limited to 'lib/std/math.zig')
-rw-r--r--lib/std/math.zig24
1 files changed, 16 insertions, 8 deletions
diff --git a/lib/std/math.zig b/lib/std/math.zig
index 94915a5ad0..77eed37304 100644
--- a/lib/std/math.zig
+++ b/lib/std/math.zig
@@ -1073,7 +1073,7 @@ test "std.math.log2_int_ceil" {
///Cast a value to a different type. If the value doesn't fit in, or can't be perfectly represented by,
///the new type, it will be converted to the closest possible representation.
pub fn lossyCast(comptime T: type, value: anytype) T {
- switch(@typeInfo(T)) {
+ switch (@typeInfo(T)) {
.Float => {
switch (@typeInfo(@TypeOf(value))) {
.Int => return @intToFloat(T, value),
@@ -1084,16 +1084,24 @@ pub fn lossyCast(comptime T: type, value: anytype) T {
}
},
.Int => {
- switch(@typeInfo(@TypeOf(value))) {
+ switch (@typeInfo(@TypeOf(value))) {
.Int, .ComptimeInt => {
- if (value > maxInt(T)) { return @as(T, maxInt(T)); }
- else if (value < minInt(T)) { return @as(T, minInt(T)); }
- else { return @intCast(T, value); }
+ if (value > maxInt(T)) {
+ return @as(T, maxInt(T));
+ } else if (value < minInt(T)) {
+ return @as(T, minInt(T));
+ } else {
+ return @intCast(T, value);
+ }
},
.Float, .ComptimeFloat => {
- if (value > maxInt(T)) { return @as(T, maxInt(T)); }
- else if (value < minInt(T)) { return @as(T, minInt(T)); }
- else { return @floatToInt(T, value); }
+ if (value > maxInt(T)) {
+ return @as(T, maxInt(T));
+ } else if (value < minInt(T)) {
+ return @as(T, minInt(T));
+ } else {
+ return @floatToInt(T, value);
+ }
},
else => @compileError("bad type"),
}