rust/library/core/src/num
Matthias Krüger cea6ba7a06
Rollup merge of #140172 - bjoernager:const-float-algebraic, r=RalfJung
Make algebraic functions into `const fn` items.

Tracking issue: #136469

This PR makes the algebraic intrinsics and the unstable, algebraic functions of `f16`, `f32`, `f64`, and `f128` into `const fn` items:

```rust
impl f16 {
    pub const fn algebraic_add(self, rhs: f16) -> f16;
    pub const fn algebraic_sub(self, rhs: f16) -> f16;
    pub const fn algebraic_mul(self, rhs: f16) -> f16;
    pub const fn algebraic_div(self, rhs: f16) -> f16;
    pub const fn algebraic_rem(self, rhs: f16) -> f16;
}

impl f32 {
    pub const fn algebraic_add(self, rhs: f32) -> f32;
    pub const fn algebraic_sub(self, rhs: f32) -> f32;
    pub const fn algebraic_mul(self, rhs: f32) -> f32;
    pub const fn algebraic_div(self, rhs: f32) -> f32;
    pub const fn algebraic_rem(self, rhs: f32) -> f32;
}

impl f64 {
    pub const fn algebraic_add(self, rhs: f64) -> f64;
    pub const fn algebraic_sub(self, rhs: f64) -> f64;
    pub const fn algebraic_mul(self, rhs: f64) -> f64;
    pub const fn algebraic_div(self, rhs: f64) -> f64;
    pub const fn algebraic_rem(self, rhs: f64) -> f64;
}

impl f128 {
    pub const fn algebraic_add(self, rhs: f128) -> f128;
    pub const fn algebraic_sub(self, rhs: f128) -> f128;
    pub const fn algebraic_mul(self, rhs: f128) -> f128;
    pub const fn algebraic_div(self, rhs: f128) -> f128;
    pub const fn algebraic_rem(self, rhs: f128) -> f128;
}

// core::intrinsics

pub const fn fadd_algebraic<T: Copy>(a: T, b: T) -> T;
pub const fn fsub_algebraic<T: Copy>(a: T, b: T) -> T;
pub const fn fmul_algebraic<T: Copy>(a: T, b: T) -> T;
pub const fn fdiv_algebraic<T: Copy>(a: T, b: T) -> T;
pub const fn frem_algebraic<T: Copy>(a: T, b: T) -> T;
```

This PR does not preserve the initial behaviour of these functions yielding non-deterministic output under Miri; it is most likely desired to reimplement this behaviour at some point.
2025-04-24 17:19:46 +02:00
..
dec2flt Rollup merge of #138034 - thaliaarchi:use-prelude-size-of, r=tgross35 2025-03-07 10:12:44 +01:00
flt2dec Add inherent versions of MaybeUninit methods for slices 2025-01-11 23:57:00 -05:00
shells diagnostic items for legacy numeric constants 2024-02-18 12:08:16 -07:00
bignum.rs Rollup merge of #134797 - spastorino:ergonomic-ref-counting-1, r=nikomatsakis 2025-03-07 19:15:33 +01:00
diy_float.rs Fix assert in diy_float 2021-07-27 16:02:35 -04:00
error.rs replace placeholder version 2024-09-03 20:54:02 +01:00
f16.rs Rollup merge of #140172 - bjoernager:const-float-algebraic, r=RalfJung 2025-04-24 17:19:46 +02:00
f32.rs Rollup merge of #140172 - bjoernager:const-float-algebraic, r=RalfJung 2025-04-24 17:19:46 +02:00
f64.rs Rollup merge of #140172 - bjoernager:const-float-algebraic, r=RalfJung 2025-04-24 17:19:46 +02:00
f128.rs Rollup merge of #140172 - bjoernager:const-float-algebraic, r=RalfJung 2025-04-24 17:19:46 +02:00
fmt.rs Fix a bunch of typos 2021-12-14 16:40:43 +01:00
int_log10.rs core: add #![warn(unreachable_pub)] 2025-01-20 18:35:32 +01:00
int_macros.rs Suggest {to,from}_ne_bytes for transmutations between arrays and integers, etc 2025-04-24 13:14:36 +07:00
int_sqrt.rs core: add #![warn(unreachable_pub)] 2025-01-20 18:35:32 +01:00
mod.rs Mention average in midpoint documentations 2025-04-24 07:44:05 +02:00
niche_types.rs Add safe new to NotAllOnes 2025-02-14 12:00:13 +00:00
nonzero.rs Mention average in midpoint documentations 2025-04-24 07:44:05 +02:00
overflow_panic.rs core: add #![warn(unreachable_pub)] 2025-01-20 18:35:32 +01:00
saturating.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
uint_macros.rs Suggest {to,from}_ne_bytes for transmutations between arrays and integers, etc 2025-04-24 13:14:36 +07:00
wrapping.rs core: add #![warn(unreachable_pub)] 2025-01-20 18:35:32 +01:00