Crates.io | midpoint |
lib.rs | midpoint |
version | 0.1.5 |
source | src |
created_at | 2022-01-30 16:40:37.878747 |
updated_at | 2022-02-01 13:37:27.048982 |
description | Extension traits offering implementations of midpoint [currently, only for primitive integers]. |
homepage | |
repository | https://github.com/JohnScience/midpoint |
max_upload_size | |
id | 524115 |
size | 29,778 |
Two-place midpoint function is the function returning an average of two values, such as values of signed or unsigned integer types, floating point types, or pointer types.
This library provides several implementations of two-place midpoint function [currently, only for primitive integers] with different properties (performance, generality, and rounding behavior) whereas the GitHub repo of the lib offers the design document, tests, runnable benchmarks, and pre-generated criterion.rs performance reports.
[dependencies]
midpoint = { version = "0.1.5" }
# Read more about features here: https://doc.rust-lang.org/cargo/reference/features.html#dependency-features
[features]
all = ["const_trait_impl", "const_fn_trait_bound", "unchecked_math", "const_inherent_unchecked_arith"]
const_trait_impl = ["midpoint/const_trait_impl"]
const_fn_trait_bound = ["midpoint/const_fn_trait_bound"]
unchecked_math = ["midpoint/unchecked_math"]
const_inherent_unchecked_arith = ["midpoint/const_inherent_unchecked_arith"]
use midpoint::MidpointViaPrimitivePromotionExt;
// With features = ["all"] or
// features = ["const_trait_impl", ...] the call can be
// performed in constant context, such as const fn
let result: i32 = (-7).midpoint_via_primitive_promotion(&-2);
assert_eq!(result, -4);