mirror of
https://github.com/ziglang/zig.git
synced 2024-11-26 23:22:44 +00:00
27 lines
617 B
Zig
27 lines
617 B
Zig
const Threshold = struct {
|
|
minimum: f32 = 0.25,
|
|
maximum: f32 = 0.75,
|
|
|
|
const Category = enum { low, medium, high };
|
|
|
|
fn categorize(t: Threshold, value: f32) Category {
|
|
assert(t.maximum >= t.minimum);
|
|
if (value < t.minimum) return .low;
|
|
if (value > t.maximum) return .high;
|
|
return .medium;
|
|
}
|
|
};
|
|
|
|
pub fn main() !void {
|
|
var threshold: Threshold = .{
|
|
.maximum = 0.20,
|
|
};
|
|
const category = threshold.categorize(0.90);
|
|
try std.io.getStdOut().writeAll(@tagName(category));
|
|
}
|
|
|
|
const std = @import("std");
|
|
const assert = std.debug.assert;
|
|
|
|
// exe=fail
|