-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
exports now include zero step and docs have more function comments
- Loading branch information
Showing
17 changed files
with
261 additions
and
103 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,28 @@ | ||
//! Module with some helper functions. | ||
|
||
const std = @import("std"); | ||
|
||
/// Casts an integer to a float. | ||
pub fn asfloat(comptime T: type, a: anytype) T { | ||
return @as(T, @floatFromInt(a)); | ||
} | ||
|
||
/// Reverse the bits of a number. | ||
pub fn bitrev(value: anytype, count: u6) @TypeOf(value) { | ||
var result: @TypeOf(value) = 0; var i: u6 = 0; while (i < count) : (i += 1) {result |= ((value >> @intCast(i)) & 1) << @intCast(count - 1 - i);} return result; | ||
} | ||
|
||
/// Calculate the combination number. | ||
pub fn c(n: anytype, k: @TypeOf(n)) @TypeOf(n) { | ||
var nck: @TypeOf(n) = 1; for (k + 1..n + 1) |i| {nck *= i;} for (2..n - k + 1) |i| {nck /= i;} return nck; | ||
} | ||
|
||
/// Calculate the product of an array. | ||
pub fn prod(comptime T: type, v: []const T) T { | ||
var result: T = 1; for (v) |value| result *= value; return result; | ||
} | ||
|
||
/// Remove the carriage return from a string. Fucking windows. | ||
pub fn uncr(string: []const u8) []const u8 { | ||
return if (string[string.len - 1] == 13) string[0..string.len - 1] else string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.