Struct fj_math::Scalar

source ·
#[repr(C)]
pub struct Scalar(_);
Expand description

A rational, finite scalar value

This is a wrapper around f64. On construction, it checks that the f64 value is not NaN. This allows Scalar to provide implementations of Eq, Ord, and Hash, enabling Scalar (and types built on top of it), to be used as keys in hash maps, hash sets, and similar types.

Implementations§

The Scalar instance that represents zero

The Scalar instance that represents one

The Scalar instance that represents two

The largest Scalar value

The Scalar instance that represents pi

The Scalar instance that represents tau

Construct a Scalar from an f64

Panics

Panics, if scalar is NaN.

Examples found in repository?
src/scalar.rs (line 55)
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
    pub fn from_u64(scalar: u64) -> Self {
        Self::from_f64(scalar as f64)
    }

    /// Convert the scalar into an `f32`
    pub fn into_f32(self) -> f32 {
        self.0 as f32
    }

    /// Convert the scalar into an `f64`
    pub fn into_f64(self) -> f64 {
        self.0
    }

    /// Convert the scalar into a `u64`
    pub fn into_u64(self) -> u64 {
        self.0 as u64
    }

    /// Indicate whether the scalar is negative
    pub fn is_negative(self) -> bool {
        self < Self::ZERO
    }

    /// Indicate whether the scalar is positive
    pub fn is_positive(self) -> bool {
        self > Self::ZERO
    }

    /// Indicate whether the scalar is zero
    pub fn is_zero(self) -> bool {
        self == Self::ZERO
    }

    /// The sign of the scalar
    ///
    /// Return `Scalar::ZERO`, if the scalar is zero, `Scalar::ONE`, if it is
    /// positive, `-Scalar::ONE`, if it is negative.
    pub fn sign(self) -> Sign {
        if self.is_negative() {
            return Sign::Negative;
        }
        if self.is_positive() {
            return Sign::Positive;
        }
        if self.is_zero() {
            return Sign::Zero;
        }

        unreachable!("Sign is neither negative, nor positive, nor zero.")
    }

    /// Compute the absolute value of the scalar
    pub fn abs(self) -> Self {
        self.0.abs().into()
    }

    /// Compute the maximum of this and another scalar
    pub fn max(self, other: impl Into<Self>) -> Self {
        self.0.max(other.into().0).into()
    }

    /// Compute the largest integer smaller than or equal to this scalar
    pub fn floor(self) -> Self {
        self.0.floor().into()
    }

    /// Compute the smallest integer larger than or equal to this scalar
    pub fn ceil(self) -> Self {
        self.0.ceil().into()
    }

    /// Round the scalar
    pub fn round(self) -> Self {
        self.0.round().into()
    }

    /// Compute the cosine
    pub fn cos(self) -> Self {
        self.0.cos().into()
    }

    /// Compute sine and cosine
    pub fn sin_cos(self) -> (Self, Self) {
        let (sin, cos) = self.0.sin_cos();
        (sin.into(), cos.into())
    }

    /// Compute the arccosine
    pub fn acos(self) -> Self {
        self.0.acos().into()
    }

    /// Compute the four-quadrant arctangent
    pub fn atan2(self, other: Self) -> Self {
        self.0.atan2(other.0).into()
    }
}

impl PartialEq for Scalar {
    fn eq(&self, other: &Self) -> bool {
        self.0 == other.0
    }
}

impl Eq for Scalar {}

impl PartialOrd for Scalar {
    fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
        self.0.partial_cmp(&other.0)
    }
}

impl Ord for Scalar {
    fn cmp(&self, other: &Self) -> cmp::Ordering {
        // Should never panic, as `from_f64` checks that the wrapped value is
        // finite.
        self.partial_cmp(other).expect("Invalid `Scalar`")
    }
}

impl Hash for Scalar {
    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
        // To the best of my knowledge, this matches the `PartialEq`
        // implementation.
        R64::from_inner(self.0).hash(state);
    }
}

impl From<f32> for Scalar {
    fn from(scalar: f32) -> Self {
        Self::from_f64(scalar.into())
    }
}

impl From<f64> for Scalar {
    fn from(scalar: f64) -> Self {
        Self::from_f64(scalar)
    }
}

impl From<Scalar> for f64 {
    fn from(scalar: Scalar) -> Self {
        scalar.into_f64()
    }
}

impl ops::Neg for Scalar {
    type Output = Self;

    fn neg(self) -> Self::Output {
        self.0.neg().into()
    }
}

impl<T: Into<Self>> ops::Add<T> for Scalar {
    type Output = Self;

    fn add(self, rhs: T) -> Self::Output {
        self.0.add(rhs.into().0).into()
    }
}

impl<T: Into<Self>> ops::Sub<T> for Scalar {
    type Output = Self;

    fn sub(self, rhs: T) -> Self::Output {
        self.0.sub(rhs.into().0).into()
    }
}

impl<T: Into<Self>> ops::Mul<T> for Scalar {
    type Output = Self;

    fn mul(self, rhs: T) -> Self::Output {
        self.0.mul(rhs.into().0).into()
    }
}

impl<T: Into<Self>> ops::Div<T> for Scalar {
    type Output = Self;

    fn div(self, rhs: T) -> Self::Output {
        self.0.div(rhs.into().0).into()
    }
}

impl<T: Into<Self>> ops::Rem<T> for Scalar {
    type Output = Self;

    fn rem(self, rhs: T) -> Self::Output {
        self.0.rem(rhs.into().0).into()
    }
}

impl<T: Into<Self>> ops::AddAssign<T> for Scalar {
    fn add_assign(&mut self, rhs: T) {
        self.0.add_assign(rhs.into().0);
        *self = self.0.into();
    }
}

impl<T: Into<Self>> ops::SubAssign<T> for Scalar {
    fn sub_assign(&mut self, rhs: T) {
        self.0.sub_assign(rhs.into().0);
        *self = self.0.into();
    }
}

impl<T: Into<Self>> ops::MulAssign<T> for Scalar {
    fn mul_assign(&mut self, rhs: T) {
        self.0.mul_assign(rhs.into().0);
        *self = self.0.into();
    }
}

impl<T: Into<Self>> ops::DivAssign<T> for Scalar {
    fn div_assign(&mut self, rhs: T) {
        self.0.div_assign(rhs.into().0);
        *self = self.0.into();
    }
}

impl<T: Into<Self>> ops::RemAssign<T> for Scalar {
    fn rem_assign(&mut self, rhs: T) {
        self.0.rem_assign(rhs.into().0);
        *self = self.0.into();
    }
}

impl num_traits::Zero for Scalar {
    fn zero() -> Self {
        Self::ZERO
    }

    fn is_zero(&self) -> bool {
        self.0.is_zero()
    }
}

impl num_traits::One for Scalar {
    fn one() -> Self {
        Self::ONE
    }
}

impl num_traits::Num for Scalar {
    type FromStrRadixErr = <f64 as num_traits::Num>::FromStrRadixErr;

    fn from_str_radix(
        str: &str,
        radix: u32,
    ) -> Result<Self, Self::FromStrRadixErr> {
        f64::from_str_radix(str, radix).map(Self::from_f64)
    }
}

impl num_traits::NumCast for Scalar {
    fn from<T: num_traits::ToPrimitive>(n: T) -> Option<Self> {
        Some(Self::from_f64(<f64 as num_traits::NumCast>::from(n)?))
    }
}

impl num_traits::Signed for Scalar {
    fn abs(&self) -> Self {
        self.0.abs().into()
    }

    fn abs_sub(&self, other: &Self) -> Self {
        <f64 as num_traits::Signed>::abs_sub(&self.0, &other.0).into()
    }

    fn signum(&self) -> Self {
        <f64 as num_traits::Signed>::signum(&self.0).into()
    }

    fn is_positive(&self) -> bool {
        <f64 as num_traits::Signed>::is_positive(&self.0)
    }

    fn is_negative(&self) -> bool {
        <f64 as num_traits::Signed>::is_negative(&self.0)
    }
}

impl num_traits::ToPrimitive for Scalar {
    fn to_i64(&self) -> Option<i64> {
        self.0.to_i64()
    }

    fn to_u64(&self) -> Option<u64> {
        self.0.to_u64()
    }
}

impl num_traits::Float for Scalar {
    fn nan() -> Self {
        panic!("`Scalar` can not represent NaN")
    }

    fn infinity() -> Self {
        Self::from_f64(f64::infinity())
    }

    fn neg_infinity() -> Self {
        Self::from_f64(f64::neg_infinity())
    }

    fn neg_zero() -> Self {
        Self::from_f64(f64::neg_zero())
    }

    fn min_value() -> Self {
        Self::from_f64(f64::min_value())
    }

    fn min_positive_value() -> Self {
        Self::from_f64(f64::min_positive_value())
    }

    fn max_value() -> Self {
        Self::from_f64(f64::max_value())
    }

    fn is_nan(self) -> bool {
        self.0.is_nan()
    }

    fn is_infinite(self) -> bool {
        self.0.is_infinite()
    }

    fn is_finite(self) -> bool {
        self.0.is_finite()
    }

    fn is_normal(self) -> bool {
        self.0.is_normal()
    }

    fn classify(self) -> std::num::FpCategory {
        self.0.classify()
    }

    fn floor(self) -> Self {
        Self::from_f64(self.0.floor())
    }

    fn ceil(self) -> Self {
        Self::from_f64(self.0.ceil())
    }

    fn round(self) -> Self {
        Self::from_f64(self.0.round())
    }

    fn trunc(self) -> Self {
        Self::from_f64(self.0.trunc())
    }

    fn fract(self) -> Self {
        Self::from_f64(self.0.fract())
    }

    fn abs(self) -> Self {
        Self::from_f64(self.0.abs())
    }

    fn signum(self) -> Self {
        Self::from_f64(self.0.signum())
    }

    fn is_sign_positive(self) -> bool {
        self.0.is_sign_positive()
    }

    fn is_sign_negative(self) -> bool {
        self.0.is_sign_negative()
    }

    fn mul_add(self, a: Self, b: Self) -> Self {
        Self::from_f64(self.0.mul_add(a.0, b.0))
    }

    fn recip(self) -> Self {
        Self::from_f64(self.0.recip())
    }

    fn powi(self, n: i32) -> Self {
        Self::from_f64(self.0.powi(n))
    }

    fn powf(self, n: Self) -> Self {
        Self::from_f64(self.0.powf(n.0))
    }

    fn sqrt(self) -> Self {
        Self::from_f64(self.0.sqrt())
    }

    fn exp(self) -> Self {
        Self::from_f64(self.0.exp())
    }

    fn exp2(self) -> Self {
        Self::from_f64(self.0.exp2())
    }

    fn ln(self) -> Self {
        Self::from_f64(self.0.ln())
    }

    fn log(self, base: Self) -> Self {
        Self::from_f64(self.0.log(base.0))
    }

    fn log2(self) -> Self {
        Self::from_f64(self.0.log2())
    }

    fn log10(self) -> Self {
        Self::from_f64(self.0.log10())
    }

    fn max(self, other: Self) -> Self {
        Self::from_f64(self.0.max(other.0))
    }

    fn min(self, other: Self) -> Self {
        Self::from_f64(self.0.min(other.0))
    }

    fn abs_sub(self, other: Self) -> Self {
        (self - other).abs()
    }

    fn cbrt(self) -> Self {
        Self::from_f64(self.0.cbrt())
    }

    fn hypot(self, other: Self) -> Self {
        Self::from_f64(self.0.hypot(other.0))
    }

    fn sin(self) -> Self {
        Self::from_f64(self.0.sin())
    }

    fn cos(self) -> Self {
        Self::from_f64(self.0.cos())
    }

    fn tan(self) -> Self {
        Self::from_f64(self.0.tan())
    }

    fn asin(self) -> Self {
        Self::from_f64(self.0.asin())
    }

    fn acos(self) -> Self {
        Self::from_f64(self.0.acos())
    }

    fn atan(self) -> Self {
        Self::from_f64(self.0.atan())
    }

    fn atan2(self, other: Self) -> Self {
        Self::from_f64(self.0.atan2(other.0))
    }

    fn sin_cos(self) -> (Self, Self) {
        let (sin, cos) = self.0.sin_cos();
        (Self::from_f64(sin), Self::from_f64(cos))
    }

    fn exp_m1(self) -> Self {
        Self::from_f64(self.0.exp_m1())
    }

    fn ln_1p(self) -> Self {
        Self::from_f64(self.0.ln_1p())
    }

    fn sinh(self) -> Self {
        Self::from_f64(self.0.sinh())
    }

    fn cosh(self) -> Self {
        Self::from_f64(self.0.cosh())
    }

    fn tanh(self) -> Self {
        Self::from_f64(self.0.tanh())
    }

    fn asinh(self) -> Self {
        Self::from_f64(self.0.asinh())
    }

    fn acosh(self) -> Self {
        Self::from_f64(self.0.acosh())
    }

    fn atanh(self) -> Self {
        Self::from_f64(self.0.atanh())
    }

Construct a Scalar from a u64

Convert the scalar into an f32

Examples found in repository?
src/vector.rs (line 263)
262
263
264
    fn from(vector: Vector<D>) -> Self {
        vector.components.map(|scalar| scalar.into_f32())
    }

Convert the scalar into an f64

Examples found in repository?
src/scalar.rs (line 197)
196
197
198
    fn from(scalar: Scalar) -> Self {
        scalar.into_f64()
    }
More examples
Hide additional examples
src/vector.rs (line 269)
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
    fn from(vector: Vector<D>) -> Self {
        vector.components.map(|scalar| scalar.into_f64())
    }
}

impl<const D: usize> From<Vector<D>> for [Scalar; D] {
    fn from(vector: Vector<D>) -> Self {
        vector.components
    }
}

impl<const D: usize> From<Vector<D>> for nalgebra::SVector<f64, D> {
    fn from(vector: Vector<D>) -> Self {
        vector.to_na()
    }
}

impl<const D: usize> ops::Neg for Vector<D> {
    type Output = Self;

    fn neg(self) -> Self::Output {
        self.to_na().neg().into()
    }
}

impl<V, const D: usize> ops::Add<V> for Vector<D>
where
    V: Into<Self>,
{
    type Output = Self;

    fn add(self, rhs: V) -> Self::Output {
        self.to_na().add(rhs.into().to_na()).into()
    }
}

impl<V, const D: usize> ops::Sub<V> for Vector<D>
where
    V: Into<Self>,
{
    type Output = Self;

    fn sub(self, rhs: V) -> Self::Output {
        self.to_na().sub(rhs.into().to_na()).into()
    }
}

impl<S, const D: usize> ops::Mul<S> for Vector<D>
where
    S: Into<Scalar>,
{
    type Output = Self;

    fn mul(self, rhs: S) -> Self::Output {
        self.to_na().mul(rhs.into().into_f64()).into()
    }
}

impl<S, const D: usize> ops::Div<S> for Vector<D>
where
    S: Into<Scalar>,
{
    type Output = Self;

    fn div(self, rhs: S) -> Self::Output {
        self.to_na().div(rhs.into().into_f64()).into()
    }

Convert the scalar into a u64

Indicate whether the scalar is negative

Examples found in repository?
src/scalar.rs (line 93)
92
93
94
95
96
97
98
99
100
101
102
103
104
    pub fn sign(self) -> Sign {
        if self.is_negative() {
            return Sign::Negative;
        }
        if self.is_positive() {
            return Sign::Positive;
        }
        if self.is_zero() {
            return Sign::Zero;
        }

        unreachable!("Sign is neither negative, nor positive, nor zero.")
    }

Indicate whether the scalar is positive

Examples found in repository?
src/scalar.rs (line 96)
92
93
94
95
96
97
98
99
100
101
102
103
104
    pub fn sign(self) -> Sign {
        if self.is_negative() {
            return Sign::Negative;
        }
        if self.is_positive() {
            return Sign::Positive;
        }
        if self.is_zero() {
            return Sign::Zero;
        }

        unreachable!("Sign is neither negative, nor positive, nor zero.")
    }

Indicate whether the scalar is zero

Examples found in repository?
src/scalar.rs (line 99)
92
93
94
95
96
97
98
99
100
101
102
103
104
    pub fn sign(self) -> Sign {
        if self.is_negative() {
            return Sign::Negative;
        }
        if self.is_positive() {
            return Sign::Positive;
        }
        if self.is_zero() {
            return Sign::Zero;
        }

        unreachable!("Sign is neither negative, nor positive, nor zero.")
    }

The sign of the scalar

Return Scalar::ZERO, if the scalar is zero, Scalar::ONE, if it is positive, -Scalar::ONE, if it is negative.

Compute the absolute value of the scalar

Examples found in repository?
src/scalar.rs (line 487)
486
487
488
    fn abs_sub(self, other: Self) -> Self {
        (self - other).abs()
    }

Compute the maximum of this and another scalar

Compute the largest integer smaller than or equal to this scalar

Compute the smallest integer larger than or equal to this scalar

Round the scalar

Compute the cosine

Compute sine and cosine

Examples found in repository?
src/circle.rs (line 150)
145
146
147
148
149
150
151
152
153
    pub fn vector_from_circle_coords(
        &self,
        vector: impl Into<Vector<1>>,
    ) -> Vector<D> {
        let angle = vector.into().t;
        let (sin, cos) = angle.sin_cos();

        self.a * cos + self.b * sin
    }

Compute the arccosine

Compute the four-quadrant arctangent

Examples found in repository?
src/circle.rs (line 127)
122
123
124
125
126
127
128
129
130
131
132
133
134
    pub fn point_to_circle_coords(
        &self,
        point: impl Into<Point<D>>,
    ) -> Point<1> {
        let vector = (point.into() - self.center).to_uv();
        let atan = Scalar::atan2(vector.v, vector.u);
        let coord = if atan >= Scalar::ZERO {
            atan
        } else {
            atan + Scalar::TAU
        };
        Point::from([coord])
    }

Trait Implementations§

Used for specifying relative comparisons.
The default tolerance to use when testing values that are close together. Read more
A test for equality that uses the absolute difference to compute the approximate equality of two numbers.
The inverse of AbsDiffEq::abs_diff_eq.
The resulting type after applying the + operator.
Performs the + operation. Read more
Performs the += operation. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Formats the value using the given formatter. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
Performs the /= operation. Read more
Returns the NaN value. Read more
Returns the infinite value. Read more
Returns the negative infinite value. Read more
Returns -0.0. Read more
Returns the smallest finite value that this type can represent. Read more
Returns the smallest positive, normalized value that this type can represent. Read more
Returns the largest finite value that this type can represent. Read more
Returns true if this value is NaN and false otherwise. Read more
Returns true if this value is positive infinity or negative infinity and false otherwise. Read more
Returns true if this number is neither infinite nor NaN. Read more
Returns true if the number is neither zero, infinite, subnormal, or NaN. Read more
Returns the floating point category of the number. If only one property is going to be tested, it is generally faster to use the specific predicate instead. Read more
Returns the largest integer less than or equal to a number. Read more
Returns the smallest integer greater than or equal to a number. Read more
Returns the nearest integer to a number. Round half-way cases away from 0.0. Read more
Return the integer part of a number. Read more
Returns the fractional part of a number. Read more
Computes the absolute value of self. Returns Float::nan() if the number is Float::nan(). Read more
Returns a number that represents the sign of self. Read more
Returns true if self is positive, including +0.0, Float::infinity(), and since Rust 1.20 also Float::nan(). Read more
Returns true if self is negative, including -0.0, Float::neg_infinity(), and since Rust 1.20 also -Float::nan(). Read more
Fused multiply-add. Computes (self * a) + b with only one rounding error, yielding a more accurate result than an unfused multiply-add. Read more
Take the reciprocal (inverse) of a number, 1/x. Read more
Raise a number to an integer power. Read more
Raise a number to a floating point power. Read more
Take the square root of a number. Read more
Returns e^(self), (the exponential function). Read more
Returns 2^(self). Read more
Returns the natural logarithm of the number. Read more
Returns the logarithm of the number with respect to an arbitrary base. Read more
Returns the base 2 logarithm of the number. Read more
Returns the base 10 logarithm of the number. Read more
Returns the maximum of the two numbers. Read more
Returns the minimum of the two numbers. Read more
The positive difference of two numbers. Read more
Take the cubic root of a number. Read more
Calculate the length of the hypotenuse of a right-angle triangle given legs of length x and y. Read more
Computes the sine of a number (in radians). Read more
Computes the cosine of a number (in radians). Read more
Computes the tangent of a number (in radians). Read more
Computes the arcsine of a number. Return value is in radians in the range [-pi/2, pi/2] or NaN if the number is outside the range [-1, 1]. Read more
Computes the arccosine of a number. Return value is in radians in the range [0, pi] or NaN if the number is outside the range [-1, 1]. Read more
Computes the arctangent of a number. Return value is in radians in the range [-pi/2, pi/2]; Read more
Computes the four quadrant arctangent of self (y) and other (x). Read more
Simultaneously computes the sine and cosine of the number, x. Returns (sin(x), cos(x)). Read more
Returns e^(self) - 1 in a way that is accurate even if the number is close to zero. Read more
Returns ln(1+n) (natural logarithm) more accurately than if the operations were performed separately. Read more
Hyperbolic sine function. Read more
Hyperbolic cosine function. Read more
Hyperbolic tangent function. Read more
Inverse hyperbolic sine function. Read more
Inverse hyperbolic cosine function. Read more
Inverse hyperbolic tangent function. Read more
Returns the mantissa, base 2 exponent, and sign as integers, respectively. The original number can be recovered by sign * mantissa * 2 ^ exponent. Read more
Returns epsilon, a small positive value. Read more
Converts radians to degrees. Read more
Converts degrees to radians. Read more
Returns a number composed of the magnitude of self and the sign of sign. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
Performs the *= operation. Read more
The resulting type after applying the - operator.
Performs the unary - operation. Read more
Convert from a string and radix (typically 2..=36). Read more
Creates a number from another value that can be converted into a primitive via the ToPrimitive trait. If the source value cannot be represented by the target type, then None is returned. Read more
Returns the multiplicative identity element of Self, 1. Read more
Sets self to the multiplicative identity element of Self, 1.
Returns true if self is equal to the multiplicative identity. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
The resulting type after applying the % operator.
Performs the % operation. Read more
Performs the %= operation. Read more
Computes the absolute value. Read more
The positive difference of two numbers. Read more
Returns the sign of the number. Read more
Returns true if the number is positive and false if the number is zero or negative.
Returns true if the number is negative and false if the number is zero or positive.
The resulting type after applying the - operator.
Performs the - operation. Read more
Performs the -= operation. Read more
Converts the value of self to an i64. If the value cannot be represented by an i64, then None is returned.
Converts the value of self to a u64. If the value cannot be represented by a u64, then None is returned.
Converts the value of self to an isize. If the value cannot be represented by an isize, then None is returned.
Converts the value of self to an i8. If the value cannot be represented by an i8, then None is returned.
Converts the value of self to an i16. If the value cannot be represented by an i16, then None is returned.
Converts the value of self to an i32. If the value cannot be represented by an i32, then None is returned.
Converts the value of self to an i128. If the value cannot be represented by an i128 (i64 under the default implementation), then None is returned. Read more
Converts the value of self to a usize. If the value cannot be represented by a usize, then None is returned.
Converts the value of self to a u8. If the value cannot be represented by a u8, then None is returned.
Converts the value of self to a u16. If the value cannot be represented by a u16, then None is returned.
Converts the value of self to a u32. If the value cannot be represented by a u32, then None is returned.
Converts the value of self to a u128. If the value cannot be represented by a u128 (u64 under the default implementation), then None is returned. Read more
Converts the value of self to an f32. Overflows may map to positive or negative inifinity, otherwise None is returned if the value cannot be represented by an f32.
Converts the value of self to an f64. Overflows may map to positive or negative inifinity, otherwise None is returned if the value cannot be represented by an f64. Read more
Returns the additive identity element of Self, 0. Read more
Returns true if self is equal to the additive identity.
Sets self to the additive identity element of Self, 0.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Returns the smallest finite value that this type can represent. Read more
Returns the smallest positive, normalized value that this type can represent. Read more
Returns epsilon, a small positive value. Read more
Returns the largest finite value that this type can represent. Read more
Returns the largest integer less than or equal to a number. Read more
Returns the smallest integer greater than or equal to a number. Read more
Returns the nearest integer to a number. Round half-way cases away from 0.0. Read more
Return the integer part of a number. Read more
Returns the fractional part of a number. Read more
Computes the absolute value of self. Returns Float::nan() if the number is Float::nan(). Read more
Returns a number that represents the sign of self. Read more
Returns true if self is positive, including +0.0, Float::infinity(), and with newer versions of Rust f64::NAN. Read more
Returns true if self is negative, including -0.0, Float::neg_infinity(), and with newer versions of Rust -f64::NAN. Read more
Fused multiply-add. Computes (self * a) + b with only one rounding error, yielding a more accurate result than an unfused multiply-add. Read more
Take the reciprocal (inverse) of a number, 1/x. Read more
Raise a number to an integer power. Read more
Raise a number to a real number power. Read more
Take the square root of a number. Read more
Returns e^(self), (the exponential function). Read more
Returns 2^(self). Read more
Returns the natural logarithm of the number. Read more
Returns the logarithm of the number with respect to an arbitrary base. Read more
Returns the base 2 logarithm of the number. Read more
Returns the base 10 logarithm of the number. Read more
Converts radians to degrees. Read more
Converts degrees to radians. Read more
Returns the maximum of the two numbers. Read more
Returns the minimum of the two numbers. Read more
The positive difference of two numbers. Read more
Take the cubic root of a number. Read more
Calculate the length of the hypotenuse of a right-angle triangle given legs of length x and y. Read more
Computes the sine of a number (in radians). Read more
Computes the cosine of a number (in radians). Read more
Computes the tangent of a number (in radians). Read more
Computes the arcsine of a number. Return value is in radians in the range [-pi/2, pi/2] or NaN if the number is outside the range [-1, 1]. Read more
Computes the arccosine of a number. Return value is in radians in the range [0, pi] or NaN if the number is outside the range [-1, 1]. Read more
Computes the arctangent of a number. Return value is in radians in the range [-pi/2, pi/2]; Read more
Computes the four quadrant arctangent of self (y) and other (x). Read more
Simultaneously computes the sine and cosine of the number, x. Returns (sin(x), cos(x)). Read more
Returns e^(self) - 1 in a way that is accurate even if the number is close to zero. Read more
Returns ln(1+n) (natural logarithm) more accurately than if the operations were performed separately. Read more
Hyperbolic sine function. Read more
Hyperbolic cosine function. Read more
Hyperbolic tangent function. Read more
Inverse hyperbolic sine function. Read more
Inverse hyperbolic cosine function. Read more
Inverse hyperbolic tangent function. Read more
Should always be Self
The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Checks if self is actually part of its subset T (and can be converted to it).
Use with care! Same as self.to_subset but without any property checks. Always succeeds.
The inclusion map: converts self to the equivalent element of its superset.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.