This file contains hidden or 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
| const print = @import("std").debug.print; | |
| const Animal = struct { | |
| const Self = @This(); | |
| speakFn: fn(*const Animal) void, | |
| pub fn speak(self: *const Self) void { | |
| self.speakFn(self); |
This file contains hidden or 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
| template <class _Ty> | |
| _NODISCARD /* constexpr */ _Ty _Common_lerp(const _Ty _ArgA, const _Ty _ArgB, const _Ty _ArgT) noexcept { | |
| // on a line intersecting {(0.0, _ArgA), (1.0, _ArgB)}, return the Y value for X == _ArgT | |
| const int _Finite_mask = (int{isfinite(_ArgA)} << 2) | (int{isfinite(_ArgB)} << 1) | int{isfinite(_ArgT)}; | |
| if (_Finite_mask == 0b111) { | |
| // 99% case, put it first; this block comes from P0811R3 | |
| if ((_ArgA <= 0 && _ArgB >= 0) || (_ArgA >= 0 && _ArgB <= 0)) { | |
| // exact, monotonic, bounded, determinate, and (for _ArgA == _ArgB == 0) consistent: | |
| return _ArgT * _ArgB + (1 - _ArgT) * _ArgA; |