copy from third_party/rust/num-traits/.cargo-checksum.json
copy to third_party/rust/num-traits-0.1.41/.cargo-checksum.json
copy from third_party/rust/num-traits/Cargo.toml
copy to third_party/rust/num-traits-0.1.41/Cargo.toml
new file mode 100644
--- /dev/null
+++ b/third_party/rust/num-traits-0.1.41/LICENSE-APACHE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
+
+APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+Copyright [yyyy] [name of copyright owner]
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
new file mode 100644
--- /dev/null
+++ b/third_party/rust/num-traits-0.1.41/LICENSE-MIT
@@ -0,0 +1,25 @@
+Copyright (c) 2014 The Rust Project Developers
+
+Permission is hereby granted, free of charge, to any
+person obtaining a copy of this software and associated
+documentation files (the "Software"), to deal in the
+Software without restriction, including without
+limitation the rights to use, copy, modify, merge,
+publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software
+is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice
+shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
+ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
+TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
+SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
copy from third_party/rust/num-traits/src/bounds.rs
copy to third_party/rust/num-traits-0.1.41/src/bounds.rs
copy from third_party/rust/num-traits/src/cast.rs
copy to third_party/rust/num-traits-0.1.41/src/cast.rs
copy from third_party/rust/num-traits/src/float.rs
copy to third_party/rust/num-traits-0.1.41/src/float.rs
copy from third_party/rust/num-traits/src/identities.rs
copy to third_party/rust/num-traits-0.1.41/src/identities.rs
copy from third_party/rust/num-traits/src/int.rs
copy to third_party/rust/num-traits-0.1.41/src/int.rs
copy from third_party/rust/num-traits/src/lib.rs
copy to third_party/rust/num-traits-0.1.41/src/lib.rs
copy from third_party/rust/num-traits/src/ops/checked.rs
copy to third_party/rust/num-traits-0.1.41/src/ops/checked.rs
new file mode 100644
--- /dev/null
+++ b/third_party/rust/num-traits-0.1.41/src/ops/mod.rs
@@ -0,0 +1,3 @@
+pub mod saturating;
+pub mod checked;
+pub mod wrapping;
new file mode 100644
--- /dev/null
+++ b/third_party/rust/num-traits-0.1.41/src/ops/saturating.rs
@@ -0,0 +1,28 @@
+/// Saturating math operations
+pub trait Saturating {
+ /// Saturating addition operator.
+ /// Returns a+b, saturating at the numeric bounds instead of overflowing.
+ fn saturating_add(self, v: Self) -> Self;
+
+ /// Saturating subtraction operator.
+ /// Returns a-b, saturating at the numeric bounds instead of overflowing.
+ fn saturating_sub(self, v: Self) -> Self;
+}
+
+macro_rules! saturating_impl {
+ ($trait_name:ident for $($t:ty)*) => {$(
+ impl $trait_name for $t {
+ #[inline]
+ fn saturating_add(self, v: Self) -> Self {
+ Self::saturating_add(self, v)
+ }
+
+ #[inline]
+ fn saturating_sub(self, v: Self) -> Self {
+ Self::saturating_sub(self, v)
+ }
+ }
+ )*}
+}
+
+saturating_impl!(Saturating for isize usize i8 u8 i16 u16 i32 u32 i64 u64);
copy from third_party/rust/num-traits/src/ops/wrapping.rs
copy to third_party/rust/num-traits-0.1.41/src/ops/wrapping.rs
copy from third_party/rust/num-traits/src/pow.rs
copy to third_party/rust/num-traits-0.1.41/src/pow.rs
copy from third_party/rust/num-traits/src/sign.rs
copy to third_party/rust/num-traits-0.1.41/src/sign.rs
--- a/third_party/rust/num-traits/.cargo-checksum.json
+++ b/third_party/rust/num-traits/.cargo-checksum.json
@@ -1,1 +1,1 @@
-{"files":{"Cargo.toml":"3d24ace42f6604297f16fb6e9a8aecb11644083bcc14eccb5d04002146444cd4","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","src/bounds.rs":"c744ca32dcb31447abc1132b2ef6f7c102d4ffa3dbc36a24a384520ec8702839","src/cast.rs":"a067d47329c30672ad9764e34a551cd566b5023f17a35673b35dbab6388043d2","src/float.rs":"fd768b5bb403cd5056d3b588074ed5571c40279d6a7da8c4f3c46ac4713f89fd","src/identities.rs":"ed67758e226fb78a14496776533a6d97d9f813294aadc73958e3005fd0e66599","src/int.rs":"b7b42dfa10423308f858216ac63fa52e26c49a7bc8900cd98de210992efc3f5f","src/lib.rs":"75b1b8b714b51f6169be13e8043bc0e9341a5aeb04e61c5446a5ce5cb241e101","src/ops/checked.rs":"bc667779636f81c7eca138c6d57252a6bb6ca4cd1f0ff706a993067044d86f94","src/ops/mod.rs":"668ea4d117bc1fdf7eaf0fe16692fa40dfbdfcbc7a2010237fe395ce0086e02e","src/ops/saturating.rs":"46821d815c90c16b2f6bec0b94b4d7ebdbddf3ea42edc0467de738c56abf6436","src/ops/wrapping.rs":"a444c7eb3366f2ad4c3a9938f1158b1994b9da4bbf9097884b5e8e27a9b581dd","src/pow.rs":"73b611ad8d595ef917871ba859ff0c25efc2382220d30568e5fbb930bf6b4daa","src/sign.rs":"732736f44c3c410f43da98eb3c8887319d94ad2c4883d614a9c353659402b315"},"package":"cacfcab5eb48250ee7d0c7896b51a2c5eec99c1feea5f32025635f5ae4b00070"}
\ No newline at end of file
+{"files":{".travis.yml":"f2329e77821e13e0b77cc97e624d76f6ccd92c929c1334cf6ac7888b01c5a481","Cargo.toml":"d6798dc92f8b83a8811446ae2e47c51564eb2b49162051b61a1eeec8bbed0da6","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"fc9a4b3719a828c9128e957ee7b9e2f795cc92a7cc50c1dda50e14126e0b4a77","RELEASES.md":"86c3e6703e6948bfc23c165a8b121930b8da4ffc7c38ab49d7a9e27b1655090e","bors.toml":"1c81ede536a37edd30fe4e622ff0531b25372403ac9475a5d6c50f14156565a2","ci/rustup.sh":"723d546a1ffefcdd5d4db9fb26dbf4128954e3991aff32932284cdc67fa5c85e","ci/test_full.sh":"c64b1d6f96baad0ea3bceb6842e7a706c4b414c99fddca55c2c30c81ae63d33a","src/bounds.rs":"d75e65f4f0e1337be06d2753ca06c23f099beb91d15215ac3230e9d441fcf4d0","src/cast.rs":"c06d1fd279b78386795384885a12742f9f31c95f364761acf0ed110184dc6bbc","src/float.rs":"841a2614519aac9f54b87e84a542df49346aa27254bd226b2dabe7966304fd0f","src/identities.rs":"f5389cf96b0d7ef55bd688961a58c4d7c0f3bd3bd48fe771948534e6bc05f29c","src/int.rs":"d6c51c943198a3aa071bfeb748101b2ce806fdef1ed6c26ef8f28f1e5a810f47","src/lib.rs":"29e4583f84b13ce2c0a6e5bbf4932183a19878e3cbab2387896b9e11c7729d5d","src/ops/checked.rs":"b2fc7ce21bca9c237f29149a553156a80d5ef94100c55128e05b946a575634c4","src/ops/mod.rs":"668ea4d117bc1fdf7eaf0fe16692fa40dfbdfcbc7a2010237fe395ce0086e02e","src/ops/saturating.rs":"46821d815c90c16b2f6bec0b94b4d7ebdbddf3ea42edc0467de738c56abf6436","src/ops/wrapping.rs":"5b274e7fc77d11ba37bb2fc98dabbbb8910f83b14d2505f775bd5a2e19445f6b","src/pow.rs":"4cedc57fc1446f436f729a68c1c4de797d316e4c1c341dead8f6ea0801c9f1ac","src/real.rs":"5e9436436593ed9c005078b9fe33477714490f959cae66ae2ae610da3eceb5f6","src/sign.rs":"f86aa7e9720698807455eabaf5f77b9fe68432fbb1a9291faf73b0c9f648d540"},"package":"e7de20f146db9d920c45ee8ed8f71681fd9ade71909b48c3acbd766aa504cf10"}
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/third_party/rust/num-traits/.travis.yml
@@ -0,0 +1,19 @@
+language: rust
+rust:
+ - 1.8.0
+ - stable
+ - beta
+ - nightly
+sudo: false
+script:
+ - cargo build --verbose
+ - ./ci/test_full.sh
+notifications:
+ email:
+ on_success: never
+branches:
+ only:
+ - master
+ - next
+ - staging
+ - trying
--- a/third_party/rust/num-traits/Cargo.toml
+++ b/third_party/rust/num-traits/Cargo.toml
@@ -7,19 +7,24 @@
#
# If you believe there's an error in this file please file an
# issue against the rust-lang/cargo repository. If you're
# editing this file be aware that the upstream Cargo.toml
# will likely look very different (and much more reasonable)
[package]
name = "num-traits"
-version = "0.1.41"
+version = "0.2.0"
authors = ["The Rust Project Developers"]
description = "Numeric traits for generic mathematics"
-homepage = "https://github.com/rust-num/num"
-documentation = "http://rust-num.github.io/num"
+homepage = "https://github.com/rust-num/num-traits"
+documentation = "https://docs.rs/num-traits"
+readme = "README.md"
keywords = ["mathematics", "numerics"]
categories = ["algorithms", "science"]
license = "MIT/Apache-2.0"
-repository = "https://github.com/rust-num/num"
+repository = "https://github.com/rust-num/num-traits"
[dependencies]
+
+[features]
+default = ["std"]
+std = []
new file mode 100644
--- /dev/null
+++ b/third_party/rust/num-traits/README.md
@@ -0,0 +1,44 @@
+# num-traits
+
+[![crate](https://img.shields.io/crates/v/num-traits.svg)](https://crates.io/crates/num-traits)
+[![documentation](https://docs.rs/num-traits/badge.svg)](https://docs.rs/num-traits)
+![minimum rustc 1.8](https://img.shields.io/badge/rustc-1.8+-red.svg)
+[![Travis status](https://travis-ci.org/rust-num/num-traits.svg?branch=master)](https://travis-ci.org/rust-num/num-traits)
+
+Numeric traits for generic mathematics in Rust.
+
+## Usage
+
+Add this to your `Cargo.toml`:
+
+```toml
+[dependencies]
+num-traits = "0.2"
+```
+
+and this to your crate root:
+
+```rust
+extern crate num_traits;
+```
+
+## Features
+
+This crate can be used without the standard library (`#![no_std]`) by disabling
+the default `std` feature. Use this in `Cargo.toml`:
+
+```toml
+[dependencies.num-traits]
+version = "0.2"
+default-features = false
+```
+
+The `Float` and `Real` traits are only available when `std` is enabled.
+
+## Releases
+
+Release notes are available in [RELEASES.md](RELEASES.md).
+
+## Compatibility
+
+The `num-traits` crate is tested for rustc 1.8 and greater.
new file mode 100644
--- /dev/null
+++ b/third_party/rust/num-traits/RELEASES.md
@@ -0,0 +1,41 @@
+# Release 0.2.0
+
+- **breaking change**: There is now a `std` feature, enabled by default, along
+ with the implication that building *without* this feature makes this a
+ `#[no_std]` crate.
+ - The `Float` and `Real` traits are only available when `std` is enabled.
+ - Otherwise, the API is unchanged, and num-traits 0.1.43 now re-exports its
+ items from num-traits 0.2 for compatibility (the [semver-trick]).
+
+**Contributors**: @cuviper, @termoshtt, @vks
+
+[semver-trick]: https://github.com/dtolnay/semver-trick
+
+# Release 0.1.43
+
+- All items are now re-exported from num-traits 0.2 for compatibility.
+
+# Release 0.1.42
+
+- [num-traits now has its own source repository][num-356] at [rust-num/num-traits][home].
+- [`ParseFloatError` now implements `Display`][22].
+- [The new `AsPrimitive` trait][17] implements generic casting with the `as` operator.
+- [The new `CheckedShl` and `CheckedShr` traits][21] implement generic
+ support for the `checked_shl` and `checked_shr` methods on primitive integers.
+- [The new `Real` trait][23] offers a subset of `Float` functionality that may be applicable to more
+ types, with a blanket implementation for all existing `T: Float` types.
+
+Thanks to @cuviper, @Enet4, @fabianschuiki, @svartalf, and @yoanlcq for their contributions!
+
+[home]: https://github.com/rust-num/num-traits
+[num-356]: https://github.com/rust-num/num/pull/356
+[17]: https://github.com/rust-num/num-traits/pull/17
+[21]: https://github.com/rust-num/num-traits/pull/21
+[22]: https://github.com/rust-num/num-traits/pull/22
+[23]: https://github.com/rust-num/num-traits/pull/23
+
+
+# Prior releases
+
+No prior release notes were kept. Thanks all the same to the many
+contributors that have made this crate what it is!
new file mode 100644
--- /dev/null
+++ b/third_party/rust/num-traits/bors.toml
@@ -0,0 +1,3 @@
+status = [
+ "continuous-integration/travis-ci/push",
+]
new file mode 100755
--- /dev/null
+++ b/third_party/rust/num-traits/ci/rustup.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+# Use rustup to locally run the same suite of tests as .travis.yml.
+# (You should first install/update 1.8.0, stable, beta, and nightly.)
+
+set -ex
+
+export TRAVIS_RUST_VERSION
+for TRAVIS_RUST_VERSION in 1.8.0 stable beta nightly; do
+ run="rustup run $TRAVIS_RUST_VERSION"
+ $run cargo build --verbose
+ $run $PWD/ci/test_full.sh
+done
new file mode 100755
--- /dev/null
+++ b/third_party/rust/num-traits/ci/test_full.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+set -ex
+
+echo Testing num-traits on rustc ${TRAVIS_RUST_VERSION}
+
+# num-traits should build and test everywhere.
+cargo build --verbose
+cargo test --verbose
+
+# test `no_std`
+cargo build --verbose --no-default-features
+cargo test --verbose --no-default-features
--- a/third_party/rust/num-traits/src/bounds.rs
+++ b/third_party/rust/num-traits/src/bounds.rs
@@ -1,12 +1,12 @@
-use std::{usize, u8, u16, u32, u64};
-use std::{isize, i8, i16, i32, i64};
-use std::{f32, f64};
-use std::num::Wrapping;
+use core::{usize, u8, u16, u32, u64};
+use core::{isize, i8, i16, i32, i64};
+use core::{f32, f64};
+use core::num::Wrapping;
/// Numbers which have upper and lower bounds
pub trait Bounded {
// FIXME (#5527): These should be associated constants
/// returns the smallest finite number this type can represent
fn min_value() -> Self;
/// returns the largest finite number this type can represent
fn max_value() -> Self;
--- a/third_party/rust/num-traits/src/cast.rs
+++ b/third_party/rust/num-traits/src/cast.rs
@@ -1,10 +1,11 @@
-use std::mem::size_of;
-use std::num::Wrapping;
+use core::f64;
+use core::mem::size_of;
+use core::num::Wrapping;
use identities::Zero;
use bounds::Bounded;
/// A generic trait for converting a value to a number.
pub trait ToPrimitive {
/// Converts the value of `self` to an `isize`.
#[inline]
@@ -221,18 +222,20 @@ impl_to_primitive_uint!(u64);
macro_rules! impl_to_primitive_float_to_float {
($SrcT:ident, $DstT:ident, $slf:expr) => (
if size_of::<$SrcT>() <= size_of::<$DstT>() {
Some($slf as $DstT)
} else {
// Make sure the value is in range for the cast.
// NaN and +-inf are cast as they are.
let n = $slf as f64;
- let max_value: $DstT = ::std::$DstT::MAX;
- if !n.is_finite() || (-max_value as f64 <= n && n <= max_value as f64) {
+ let max_value: $DstT = ::core::$DstT::MAX;
+ if n != n || n == f64::INFINITY || n == f64::NEG_INFINITY
+ || (-max_value as f64 <= n && n <= max_value as f64)
+ {
Some($slf as $DstT)
} else {
None
}
}
)
}
@@ -447,20 +450,88 @@ impl_num_cast!(f32, to_f32);
impl_num_cast!(f64, to_f64);
impl<T: NumCast> NumCast for Wrapping<T> {
fn from<U: ToPrimitive>(n: U) -> Option<Self> {
T::from(n).map(Wrapping)
}
}
+/// A generic interface for casting between machine scalars with the
+/// `as` operator, which admits narrowing and precision loss.
+/// Implementers of this trait AsPrimitive should behave like a primitive
+/// numeric type (e.g. a newtype around another primitive), and the
+/// intended conversion must never fail.
+///
+/// # Examples
+///
+/// ```
+/// # use num_traits::AsPrimitive;
+/// let three: i32 = (3.14159265f32).as_();
+/// assert_eq!(three, 3);
+/// ```
+///
+/// # Safety
+///
+/// Currently, some uses of the `as` operator are not entirely safe.
+/// In particular, it is undefined behavior if:
+///
+/// - A truncated floating point value cannot fit in the target integer
+/// type ([#10184](https://github.com/rust-lang/rust/issues/10184));
+///
+/// ```ignore
+/// # use num_traits::AsPrimitive;
+/// let x: u8 = (1.04E+17).as_(); // UB
+/// ```
+///
+/// - Or a floating point value does not fit in another floating
+/// point type ([#15536](https://github.com/rust-lang/rust/issues/15536)).
+///
+/// ```ignore
+/// # use num_traits::AsPrimitive;
+/// let x: f32 = (1e300f64).as_(); // UB
+/// ```
+///
+pub trait AsPrimitive<T>: 'static + Copy
+where
+ T: 'static + Copy
+{
+ /// Convert a value to another, using the `as` operator.
+ fn as_(self) -> T;
+}
+
+macro_rules! impl_as_primitive {
+ ($T: ty => $( $U: ty ),* ) => {
+ $(
+ impl AsPrimitive<$U> for $T {
+ #[inline] fn as_(self) -> $U { self as $U }
+ }
+ )*
+ };
+}
+
+impl_as_primitive!(u8 => char, u8, i8, u16, i16, u32, i32, u64, isize, usize, i64, f32, f64);
+impl_as_primitive!(i8 => u8, i8, u16, i16, u32, i32, u64, isize, usize, i64, f32, f64);
+impl_as_primitive!(u16 => u8, i8, u16, i16, u32, i32, u64, isize, usize, i64, f32, f64);
+impl_as_primitive!(i16 => u8, i8, u16, i16, u32, i32, u64, isize, usize, i64, f32, f64);
+impl_as_primitive!(u32 => u8, i8, u16, i16, u32, i32, u64, isize, usize, i64, f32, f64);
+impl_as_primitive!(i32 => u8, i8, u16, i16, u32, i32, u64, isize, usize, i64, f32, f64);
+impl_as_primitive!(u64 => u8, i8, u16, i16, u32, i32, u64, isize, usize, i64, f32, f64);
+impl_as_primitive!(i64 => u8, i8, u16, i16, u32, i32, u64, isize, usize, i64, f32, f64);
+impl_as_primitive!(usize => u8, i8, u16, i16, u32, i32, u64, isize, usize, i64, f32, f64);
+impl_as_primitive!(isize => u8, i8, u16, i16, u32, i32, u64, isize, usize, i64, f32, f64);
+impl_as_primitive!(f32 => u8, i8, u16, i16, u32, i32, u64, isize, usize, i64, f32, f64);
+impl_as_primitive!(f64 => u8, i8, u16, i16, u32, i32, u64, isize, usize, i64, f32, f64);
+impl_as_primitive!(char => char, u8, i8, u16, i16, u32, i32, u64, isize, usize, i64);
+impl_as_primitive!(bool => u8, i8, u16, i16, u32, i32, u64, isize, usize, i64);
+
#[test]
fn to_primitive_float() {
- use std::f32;
- use std::f64;
+ use core::f32;
+ use core::f64;
let f32_toolarge = 1e39f64;
assert_eq!(f32_toolarge.to_f32(), None);
assert_eq!((f32::MAX as f64).to_f32(), Some(f32::MAX));
assert_eq!((-f32::MAX as f64).to_f32(), Some(-f32::MAX));
assert_eq!(f64::INFINITY.to_f32(), Some(f32::INFINITY));
assert_eq!((f64::NEG_INFINITY).to_f32(), Some(f32::NEG_INFINITY));
assert!((f64::NAN).to_f32().map_or(false, |f| f.is_nan()));
@@ -504,8 +575,20 @@ fn wrapping_is_fromprimitive() {
require_fromprimitive(&Wrapping(42));
}
#[test]
fn wrapping_is_numcast() {
fn require_numcast<T: NumCast>(_: &T) {}
require_numcast(&Wrapping(42));
}
+
+#[test]
+fn as_primitive() {
+ let x: f32 = (1.625f64).as_();
+ assert_eq!(x, 1.625f32);
+
+ let x: f32 = (3.14159265358979323846f64).as_();
+ assert_eq!(x, 3.1415927f32);
+
+ let x: u8 = (768i16).as_();
+ assert_eq!(x, 0);
+}
--- a/third_party/rust/num-traits/src/float.rs
+++ b/third_party/rust/num-traits/src/float.rs
@@ -1,20 +1,29 @@
+#[cfg(feature = "std")]
use std::mem;
+#[cfg(feature = "std")]
use std::ops::Neg;
+#[cfg(feature = "std")]
use std::num::FpCategory;
// Used for default implementation of `epsilon`
+#[cfg(feature = "std")]
use std::f32;
+#[cfg(feature = "std")]
use {Num, NumCast};
// FIXME: these doctests aren't actually helpful, because they're using and
// testing the inherent methods directly, not going through `Float`.
+/// Generic trait for floating point numbers
+///
+/// This trait is only available with the `std` feature.
+#[cfg(feature = "std")]
pub trait Float
: Num
+ Copy
+ NumCast
+ PartialOrd
+ Neg<Output = Self>
{
/// Returns the `NaN` value.
@@ -918,16 +927,17 @@ pub trait Float
/// let abs_difference = (sign_f * mantissa_f * exponent_f - num).abs();
///
/// assert!(abs_difference < 1e-10);
/// ```
/// [floating-point]: ../../../../../reference.html#machine-types
fn integer_decode(self) -> (u64, i16, i8);
}
+#[cfg(feature = "std")]
macro_rules! float_impl {
($T:ident $decode:ident) => (
impl Float for $T {
#[inline]
fn nan() -> Self {
::std::$T::NAN
}
@@ -1214,16 +1224,17 @@ macro_rules! float_impl {
#[inline]
fn integer_decode(self) -> (u64, i16, i8) {
$decode(self)
}
}
)
}
+#[cfg(feature = "std")]
fn integer_decode_f32(f: f32) -> (u64, i16, i8) {
let bits: u32 = unsafe { mem::transmute(f) };
let sign: i8 = if bits >> 31 == 0 {
1
} else {
-1
};
let mut exponent: i16 = ((bits >> 23) & 0xff) as i16;
@@ -1232,16 +1243,17 @@ fn integer_decode_f32(f: f32) -> (u64, i
} else {
(bits & 0x7fffff) | 0x800000
};
// Exponent bias + mantissa shift
exponent -= 127 + 23;
(mantissa as u64, exponent, sign)
}
+#[cfg(feature = "std")]
fn integer_decode_f64(f: f64) -> (u64, i16, i8) {
let bits: u64 = unsafe { mem::transmute(f) };
let sign: i8 = if bits >> 63 == 0 {
1
} else {
-1
};
let mut exponent: i16 = ((bits >> 52) & 0x7ff) as i16;
@@ -1250,34 +1262,36 @@ fn integer_decode_f64(f: f64) -> (u64, i
} else {
(bits & 0xfffffffffffff) | 0x10000000000000
};
// Exponent bias + mantissa shift
exponent -= 1023 + 52;
(mantissa, exponent, sign)
}
+#[cfg(feature = "std")]
float_impl!(f32 integer_decode_f32);
+#[cfg(feature = "std")]
float_impl!(f64 integer_decode_f64);
macro_rules! float_const_impl {
($(#[$doc:meta] $constant:ident,)+) => (
#[allow(non_snake_case)]
pub trait FloatConst {
$(#[$doc] fn $constant() -> Self;)+
}
float_const_impl! { @float f32, $($constant,)+ }
float_const_impl! { @float f64, $($constant,)+ }
);
(@float $T:ident, $($constant:ident,)+) => (
impl FloatConst for $T {
$(
#[inline]
fn $constant() -> Self {
- ::std::$T::consts::$constant
+ ::core::$T::consts::$constant
}
)+
}
);
}
float_const_impl! {
#[doc = "Return Euler’s number."]
@@ -1309,23 +1323,23 @@ float_const_impl! {
#[doc = "Return `log2(e)`."]
LOG2_E,
#[doc = "Return Archimedes’ constant."]
PI,
#[doc = "Return `sqrt(2.0)`."]
SQRT_2,
}
-#[cfg(test)]
+#[cfg(all(test, feature = "std"))]
mod tests {
use Float;
#[test]
fn convert_deg_rad() {
- use std::f64::consts;
+ use core::f64::consts;
const DEG_RAD_PAIRS: [(f64, f64); 7] = [
(0.0, 0.),
(22.5, consts::FRAC_PI_8),
(30.0, consts::FRAC_PI_6),
(45.0, consts::FRAC_PI_4),
(60.0, consts::FRAC_PI_3),
(90.0, consts::FRAC_PI_2),
--- a/third_party/rust/num-traits/src/identities.rs
+++ b/third_party/rust/num-traits/src/identities.rs
@@ -1,10 +1,10 @@
-use std::ops::{Add, Mul};
-use std::num::Wrapping;
+use core::ops::{Add, Mul};
+use core::num::Wrapping;
/// Defines an additive identity element for `Self`.
pub trait Zero: Sized + Add<Self, Output = Self> {
/// Returns the additive identity element of `Self`, `0`.
///
/// # Laws
///
/// ```{.text}
--- a/third_party/rust/num-traits/src/int.rs
+++ b/third_party/rust/num-traits/src/int.rs
@@ -1,9 +1,9 @@
-use std::ops::{Not, BitAnd, BitOr, BitXor, Shl, Shr};
+use core::ops::{Not, BitAnd, BitOr, BitXor, Shl, Shr};
use {Num, NumCast};
use bounds::Bounded;
use ops::checked::*;
use ops::saturating::Saturating;
pub trait PrimInt
: Sized
--- a/third_party/rust/num-traits/src/lib.rs
+++ b/third_party/rust/num-traits/src/lib.rs
@@ -4,41 +4,55 @@
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//! Numeric traits for generic mathematics
-#![doc(html_logo_url = "https://rust-num.github.io/num/rust-logo-128x128-blk-v2.png",
- html_favicon_url = "https://rust-num.github.io/num/favicon.ico",
- html_root_url = "https://rust-num.github.io/num/",
- html_playground_url = "http://play.integer32.com/")]
+//!
+//! ## Compatibility
+//!
+//! The `num-traits` crate is tested for rustc 1.8 and greater.
+
+#![doc(html_root_url = "https://docs.rs/num-traits/0.2")]
+
+#![deny(unconditional_recursion)]
-use std::ops::{Add, Sub, Mul, Div, Rem};
-use std::ops::{AddAssign, SubAssign, MulAssign, DivAssign, RemAssign};
-use std::num::Wrapping;
+#![cfg_attr(not(feature = "std"), no_std)]
+#[cfg(feature = "std")]
+extern crate core;
+
+use core::ops::{Add, Sub, Mul, Div, Rem};
+use core::ops::{AddAssign, SubAssign, MulAssign, DivAssign, RemAssign};
+use core::num::Wrapping;
+use core::fmt;
pub use bounds::Bounded;
-pub use float::{Float, FloatConst};
+#[cfg(feature = "std")]
+pub use float::Float;
+pub use float::FloatConst;
+// pub use real::Real; // NOTE: Don't do this, it breaks `use num_traits::*;`.
pub use identities::{Zero, One, zero, one};
-pub use ops::checked::*;
-pub use ops::wrapping::*;
+pub use ops::checked::{CheckedAdd, CheckedSub, CheckedMul, CheckedDiv, CheckedShl, CheckedShr};
+pub use ops::wrapping::{WrappingAdd, WrappingMul, WrappingSub};
pub use ops::saturating::Saturating;
pub use sign::{Signed, Unsigned, abs, abs_sub, signum};
-pub use cast::*;
+pub use cast::{AsPrimitive, FromPrimitive, ToPrimitive, NumCast, cast};
pub use int::PrimInt;
pub use pow::{pow, checked_pow};
pub mod identities;
pub mod sign;
pub mod ops;
pub mod bounds;
pub mod float;
+#[cfg(feature = "std")]
+pub mod real;
pub mod cast;
pub mod int;
pub mod pow;
/// The base trait for numeric types, covering `0` and `1` values,
/// comparisons, basic numeric operations, and string conversion.
pub trait Num: PartialEq + Zero + One + NumOps
{
@@ -124,20 +138,20 @@ impl<T> NumAssign for T where T: Num + N
/// This is automatically implemented for types which implement the operators.
pub trait NumAssignRef: NumAssign + for<'r> NumAssignOps<&'r Self> {}
impl<T> NumAssignRef for T where T: NumAssign + for<'r> NumAssignOps<&'r T> {}
macro_rules! int_trait_impl {
($name:ident for $($t:ty)*) => ($(
impl $name for $t {
- type FromStrRadixErr = ::std::num::ParseIntError;
+ type FromStrRadixErr = ::core::num::ParseIntError;
#[inline]
fn from_str_radix(s: &str, radix: u32)
- -> Result<Self, ::std::num::ParseIntError>
+ -> Result<Self, ::core::num::ParseIntError>
{
<$t>::from_str_radix(s, radix)
}
}
)*)
}
int_trait_impl!(Num for usize u8 u16 u32 u64 isize i8 i16 i32 i64);
@@ -153,42 +167,53 @@ impl<T: Num> Num for Wrapping<T>
}
#[derive(Debug)]
pub enum FloatErrorKind {
Empty,
Invalid,
}
-// FIXME: std::num::ParseFloatError is stable in 1.0, but opaque to us,
+// FIXME: core::num::ParseFloatError is stable in 1.0, but opaque to us,
// so there's not really any way for us to reuse it.
#[derive(Debug)]
pub struct ParseFloatError {
pub kind: FloatErrorKind,
}
+impl fmt::Display for ParseFloatError {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ let description = match self.kind {
+ FloatErrorKind::Empty => "cannot parse float from empty string",
+ FloatErrorKind::Invalid => "invalid float literal",
+ };
+
+ description.fmt(f)
+ }
+}
+
// FIXME: The standard library from_str_radix on floats was deprecated, so we're stuck
// with this implementation ourselves until we want to make a breaking change.
// (would have to drop it from `Num` though)
macro_rules! float_trait_impl {
- ($name:ident for $($t:ty)*) => ($(
+ ($name:ident for $($t:ident)*) => ($(
impl $name for $t {
type FromStrRadixErr = ParseFloatError;
fn from_str_radix(src: &str, radix: u32)
-> Result<Self, Self::FromStrRadixErr>
{
use self::FloatErrorKind::*;
use self::ParseFloatError as PFE;
// Special values
match src {
- "inf" => return Ok(Float::infinity()),
- "-inf" => return Ok(Float::neg_infinity()),
- "NaN" => return Ok(Float::nan()),
+ "inf" => return Ok(core::$t::INFINITY),
+ "-inf" => return Ok(core::$t::NEG_INFINITY),
+ "NaN" => return Ok(core::$t::NAN),
_ => {},
}
fn slice_shift_char(src: &str) -> Option<(char, &str)> {
src.chars().nth(0).map(|ch| (ch, &src[1..]))
}
let (is_positive, src) = match slice_shift_char(src) {
@@ -219,25 +244,25 @@ macro_rules! float_trait_impl {
} else {
sig = sig - ((digit as isize) as $t);
}
// Detect overflow by comparing to last value, except
// if we've not seen any non-zero digits.
if prev_sig != 0.0 {
if is_positive && sig <= prev_sig
- { return Ok(Float::infinity()); }
+ { return Ok(core::$t::INFINITY); }
if !is_positive && sig >= prev_sig
- { return Ok(Float::neg_infinity()); }
+ { return Ok(core::$t::NEG_INFINITY); }
// Detect overflow by reversing the shift-and-add process
if is_positive && (prev_sig != (sig - digit as $t) / radix as $t)
- { return Ok(Float::infinity()); }
+ { return Ok(core::$t::INFINITY); }
if !is_positive && (prev_sig != (sig + digit as $t) / radix as $t)
- { return Ok(Float::neg_infinity()); }
+ { return Ok(core::$t::NEG_INFINITY); }
}
prev_sig = sig;
},
None => match c {
'e' | 'E' | 'p' | 'P' => {
exp_info = Some((c, i + 1));
break; // start of exponent
},
@@ -263,19 +288,19 @@ macro_rules! float_trait_impl {
// add/subtract current digit depending on sign
sig = if is_positive {
sig + (digit as $t) * power
} else {
sig - (digit as $t) * power
};
// Detect overflow by comparing to last value
if is_positive && sig < prev_sig
- { return Ok(Float::infinity()); }
+ { return Ok(core::$t::INFINITY); }
if !is_positive && sig > prev_sig
- { return Ok(Float::neg_infinity()); }
+ { return Ok(core::$t::NEG_INFINITY); }
prev_sig = sig;
},
None => match c {
'e' | 'E' | 'p' | 'P' => {
exp_info = Some((c, i + 1));
break; // start of exponent
},
_ => {
@@ -299,19 +324,25 @@ macro_rules! float_trait_impl {
let src = &src[offset..];
let (is_positive, exp) = match slice_shift_char(src) {
Some(('-', src)) => (false, src.parse::<usize>()),
Some(('+', src)) => (true, src.parse::<usize>()),
Some((_, _)) => (true, src.parse::<usize>()),
None => return Err(PFE { kind: Invalid }),
};
+ #[cfg(feature = "std")]
+ fn pow(base: $t, exp: usize) -> $t {
+ Float::powi(base, exp as i32)
+ }
+ // otherwise uses the generic `pow` from the root
+
match (is_positive, exp) {
- (true, Ok(exp)) => base.powi(exp as i32),
- (false, Ok(exp)) => 1.0 / base.powi(exp as i32),
+ (true, Ok(exp)) => pow(base, exp),
+ (false, Ok(exp)) => 1.0 / pow(base, exp),
(_, Err(_)) => return Err(PFE { kind: Invalid }),
}
},
None => 1.0, // no exponent
};
Ok(sig * exp)
}
--- a/third_party/rust/num-traits/src/ops/checked.rs
+++ b/third_party/rust/num-traits/src/ops/checked.rs
@@ -1,9 +1,9 @@
-use std::ops::{Add, Sub, Mul, Div};
+use core::ops::{Add, Sub, Mul, Div, Shl, Shr};
/// Performs addition that returns `None` instead of wrapping around on
/// overflow.
pub trait CheckedAdd: Sized + Add<Self, Output=Self> {
/// Adds two numbers, checking for overflow. If overflow happens, `None` is
/// returned.
fn checked_add(&self, v: &Self) -> Option<Self>;
}
@@ -85,8 +85,78 @@ checked_impl!(CheckedDiv, checked_div, u
checked_impl!(CheckedDiv, checked_div, usize);
checked_impl!(CheckedDiv, checked_div, i8);
checked_impl!(CheckedDiv, checked_div, i16);
checked_impl!(CheckedDiv, checked_div, i32);
checked_impl!(CheckedDiv, checked_div, i64);
checked_impl!(CheckedDiv, checked_div, isize);
+/// Performs a left shift that returns `None` on overflow.
+pub trait CheckedShl: Sized + Shl<u32, Output=Self> {
+ /// Shifts a number to the left, checking for overflow. If overflow happens,
+ /// `None` is returned.
+ ///
+ /// ```
+ /// use num_traits::CheckedShl;
+ ///
+ /// let x: u16 = 0x0001;
+ ///
+ /// assert_eq!(CheckedShl::checked_shl(&x, 0), Some(0x0001));
+ /// assert_eq!(CheckedShl::checked_shl(&x, 1), Some(0x0002));
+ /// assert_eq!(CheckedShl::checked_shl(&x, 15), Some(0x8000));
+ /// assert_eq!(CheckedShl::checked_shl(&x, 16), None);
+ /// ```
+ fn checked_shl(&self, rhs: u32) -> Option<Self>;
+}
+
+macro_rules! checked_shift_impl {
+ ($trait_name:ident, $method:ident, $t:ty) => {
+ impl $trait_name for $t {
+ #[inline]
+ fn $method(&self, rhs: u32) -> Option<$t> {
+ <$t>::$method(*self, rhs)
+ }
+ }
+ }
+}
+
+checked_shift_impl!(CheckedShl, checked_shl, u8);
+checked_shift_impl!(CheckedShl, checked_shl, u16);
+checked_shift_impl!(CheckedShl, checked_shl, u32);
+checked_shift_impl!(CheckedShl, checked_shl, u64);
+checked_shift_impl!(CheckedShl, checked_shl, usize);
+
+checked_shift_impl!(CheckedShl, checked_shl, i8);
+checked_shift_impl!(CheckedShl, checked_shl, i16);
+checked_shift_impl!(CheckedShl, checked_shl, i32);
+checked_shift_impl!(CheckedShl, checked_shl, i64);
+checked_shift_impl!(CheckedShl, checked_shl, isize);
+
+/// Performs a right shift that returns `None` on overflow.
+pub trait CheckedShr: Sized + Shr<u32, Output=Self> {
+ /// Shifts a number to the left, checking for overflow. If overflow happens,
+ /// `None` is returned.
+ ///
+ /// ```
+ /// use num_traits::CheckedShr;
+ ///
+ /// let x: u16 = 0x8000;
+ ///
+ /// assert_eq!(CheckedShr::checked_shr(&x, 0), Some(0x8000));
+ /// assert_eq!(CheckedShr::checked_shr(&x, 1), Some(0x4000));
+ /// assert_eq!(CheckedShr::checked_shr(&x, 15), Some(0x0001));
+ /// assert_eq!(CheckedShr::checked_shr(&x, 16), None);
+ /// ```
+ fn checked_shr(&self, rhs: u32) -> Option<Self>;
+}
+
+checked_shift_impl!(CheckedShr, checked_shr, u8);
+checked_shift_impl!(CheckedShr, checked_shr, u16);
+checked_shift_impl!(CheckedShr, checked_shr, u32);
+checked_shift_impl!(CheckedShr, checked_shr, u64);
+checked_shift_impl!(CheckedShr, checked_shr, usize);
+
+checked_shift_impl!(CheckedShr, checked_shr, i8);
+checked_shift_impl!(CheckedShr, checked_shr, i16);
+checked_shift_impl!(CheckedShr, checked_shr, i32);
+checked_shift_impl!(CheckedShr, checked_shr, i64);
+checked_shift_impl!(CheckedShr, checked_shr, isize);
--- a/third_party/rust/num-traits/src/ops/wrapping.rs
+++ b/third_party/rust/num-traits/src/ops/wrapping.rs
@@ -1,10 +1,10 @@
-use std::ops::{Add, Sub, Mul};
-use std::num::Wrapping;
+use core::ops::{Add, Sub, Mul};
+use core::num::Wrapping;
macro_rules! wrapping_impl {
($trait_name:ident, $method:ident, $t:ty) => {
impl $trait_name for $t {
#[inline]
fn $method(&self, v: &Self) -> Self {
<$t>::$method(*self, *v)
}
--- a/third_party/rust/num-traits/src/pow.rs
+++ b/third_party/rust/num-traits/src/pow.rs
@@ -1,9 +1,9 @@
-use std::ops::Mul;
+use core::ops::Mul;
use {One, CheckedMul};
/// Raises a value to the power of exp, using exponentiation by squaring.
///
/// # Example
///
/// ```rust
/// use num_traits::pow;
new file mode 100644
--- /dev/null
+++ b/third_party/rust/num-traits/src/real.rs
@@ -0,0 +1,926 @@
+use std::ops::Neg;
+
+use {Num, NumCast, Float};
+
+// NOTE: These doctests have the same issue as those in src/float.rs.
+// They're testing the inherent methods directly, and not those of `Real`.
+
+/// A trait for real number types that do not necessarily have
+/// floating-point-specific characteristics such as NaN and infinity.
+///
+/// See [this Wikipedia article](https://en.wikipedia.org/wiki/Real_data_type)
+/// for a list of data types that could meaningfully implement this trait.
+///
+/// This trait is only available with the `std` feature.
+pub trait Real
+ : Num
+ + Copy
+ + NumCast
+ + PartialOrd
+ + Neg<Output = Self>
+{
+ /// Returns the smallest finite value that this type can represent.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ /// use std::f64;
+ ///
+ /// let x: f64 = Real::min_value();
+ ///
+ /// assert_eq!(x, f64::MIN);
+ /// ```
+ fn min_value() -> Self;
+
+ /// Returns the smallest positive, normalized value that this type can represent.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ /// use std::f64;
+ ///
+ /// let x: f64 = Real::min_positive_value();
+ ///
+ /// assert_eq!(x, f64::MIN_POSITIVE);
+ /// ```
+ fn min_positive_value() -> Self;
+
+ /// Returns epsilon, a small positive value.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ /// use std::f64;
+ ///
+ /// let x: f64 = Real::epsilon();
+ ///
+ /// assert_eq!(x, f64::EPSILON);
+ /// ```
+ ///
+ /// # Panics
+ ///
+ /// The default implementation will panic if `f32::EPSILON` cannot
+ /// be cast to `Self`.
+ fn epsilon() -> Self;
+
+ /// Returns the largest finite value that this type can represent.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ /// use std::f64;
+ ///
+ /// let x: f64 = Real::max_value();
+ /// assert_eq!(x, f64::MAX);
+ /// ```
+ fn max_value() -> Self;
+
+ /// Returns the largest integer less than or equal to a number.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ ///
+ /// let f = 3.99;
+ /// let g = 3.0;
+ ///
+ /// assert_eq!(f.floor(), 3.0);
+ /// assert_eq!(g.floor(), 3.0);
+ /// ```
+ fn floor(self) -> Self;
+
+ /// Returns the smallest integer greater than or equal to a number.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ ///
+ /// let f = 3.01;
+ /// let g = 4.0;
+ ///
+ /// assert_eq!(f.ceil(), 4.0);
+ /// assert_eq!(g.ceil(), 4.0);
+ /// ```
+ fn ceil(self) -> Self;
+
+ /// Returns the nearest integer to a number. Round half-way cases away from
+ /// `0.0`.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ ///
+ /// let f = 3.3;
+ /// let g = -3.3;
+ ///
+ /// assert_eq!(f.round(), 3.0);
+ /// assert_eq!(g.round(), -3.0);
+ /// ```
+ fn round(self) -> Self;
+
+ /// Return the integer part of a number.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ ///
+ /// let f = 3.3;
+ /// let g = -3.7;
+ ///
+ /// assert_eq!(f.trunc(), 3.0);
+ /// assert_eq!(g.trunc(), -3.0);
+ /// ```
+ fn trunc(self) -> Self;
+
+ /// Returns the fractional part of a number.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ ///
+ /// let x = 3.5;
+ /// let y = -3.5;
+ /// let abs_difference_x = (x.fract() - 0.5).abs();
+ /// let abs_difference_y = (y.fract() - (-0.5)).abs();
+ ///
+ /// assert!(abs_difference_x < 1e-10);
+ /// assert!(abs_difference_y < 1e-10);
+ /// ```
+ fn fract(self) -> Self;
+
+ /// Computes the absolute value of `self`. Returns `Float::nan()` if the
+ /// number is `Float::nan()`.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ /// use std::f64;
+ ///
+ /// let x = 3.5;
+ /// let y = -3.5;
+ ///
+ /// let abs_difference_x = (x.abs() - x).abs();
+ /// let abs_difference_y = (y.abs() - (-y)).abs();
+ ///
+ /// assert!(abs_difference_x < 1e-10);
+ /// assert!(abs_difference_y < 1e-10);
+ ///
+ /// assert!(::num_traits::Float::is_nan(f64::NAN.abs()));
+ /// ```
+ fn abs(self) -> Self;
+
+ /// Returns a number that represents the sign of `self`.
+ ///
+ /// - `1.0` if the number is positive, `+0.0` or `Float::infinity()`
+ /// - `-1.0` if the number is negative, `-0.0` or `Float::neg_infinity()`
+ /// - `Float::nan()` if the number is `Float::nan()`
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ /// use std::f64;
+ ///
+ /// let f = 3.5;
+ ///
+ /// assert_eq!(f.signum(), 1.0);
+ /// assert_eq!(f64::NEG_INFINITY.signum(), -1.0);
+ ///
+ /// assert!(f64::NAN.signum().is_nan());
+ /// ```
+ fn signum(self) -> Self;
+
+ /// Returns `true` if `self` is positive, including `+0.0`,
+ /// `Float::infinity()`, and with newer versions of Rust `f64::NAN`.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ /// use std::f64;
+ ///
+ /// let neg_nan: f64 = -f64::NAN;
+ ///
+ /// let f = 7.0;
+ /// let g = -7.0;
+ ///
+ /// assert!(f.is_sign_positive());
+ /// assert!(!g.is_sign_positive());
+ /// assert!(!neg_nan.is_sign_positive());
+ /// ```
+ fn is_sign_positive(self) -> bool;
+
+ /// Returns `true` if `self` is negative, including `-0.0`,
+ /// `Float::neg_infinity()`, and with newer versions of Rust `-f64::NAN`.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ /// use std::f64;
+ ///
+ /// let nan: f64 = f64::NAN;
+ ///
+ /// let f = 7.0;
+ /// let g = -7.0;
+ ///
+ /// assert!(!f.is_sign_negative());
+ /// assert!(g.is_sign_negative());
+ /// assert!(!nan.is_sign_negative());
+ /// ```
+ fn is_sign_negative(self) -> bool;
+
+ /// Fused multiply-add. Computes `(self * a) + b` with only one rounding
+ /// error. This produces a more accurate result with better performance than
+ /// a separate multiplication operation followed by an add.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ ///
+ /// let m = 10.0;
+ /// let x = 4.0;
+ /// let b = 60.0;
+ ///
+ /// // 100.0
+ /// let abs_difference = (m.mul_add(x, b) - (m*x + b)).abs();
+ ///
+ /// assert!(abs_difference < 1e-10);
+ /// ```
+ fn mul_add(self, a: Self, b: Self) -> Self;
+
+ /// Take the reciprocal (inverse) of a number, `1/x`.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ ///
+ /// let x = 2.0;
+ /// let abs_difference = (x.recip() - (1.0/x)).abs();
+ ///
+ /// assert!(abs_difference < 1e-10);
+ /// ```
+ fn recip(self) -> Self;
+
+ /// Raise a number to an integer power.
+ ///
+ /// Using this function is generally faster than using `powf`
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ ///
+ /// let x = 2.0;
+ /// let abs_difference = (x.powi(2) - x*x).abs();
+ ///
+ /// assert!(abs_difference < 1e-10);
+ /// ```
+ fn powi(self, n: i32) -> Self;
+
+ /// Raise a number to a real number power.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ ///
+ /// let x = 2.0;
+ /// let abs_difference = (x.powf(2.0) - x*x).abs();
+ ///
+ /// assert!(abs_difference < 1e-10);
+ /// ```
+ fn powf(self, n: Self) -> Self;
+
+ /// Take the square root of a number.
+ ///
+ /// Returns NaN if `self` is a negative floating-point number.
+ ///
+ /// # Panics
+ ///
+ /// If the implementing type doesn't support NaN, this method should panic if `self < 0`.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ ///
+ /// let positive = 4.0;
+ /// let negative = -4.0;
+ ///
+ /// let abs_difference = (positive.sqrt() - 2.0).abs();
+ ///
+ /// assert!(abs_difference < 1e-10);
+ /// assert!(::num_traits::Float::is_nan(negative.sqrt()));
+ /// ```
+ fn sqrt(self) -> Self;
+
+ /// Returns `e^(self)`, (the exponential function).
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ ///
+ /// let one = 1.0;
+ /// // e^1
+ /// let e = one.exp();
+ ///
+ /// // ln(e) - 1 == 0
+ /// let abs_difference = (e.ln() - 1.0).abs();
+ ///
+ /// assert!(abs_difference < 1e-10);
+ /// ```
+ fn exp(self) -> Self;
+
+ /// Returns `2^(self)`.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ ///
+ /// let f = 2.0;
+ ///
+ /// // 2^2 - 4 == 0
+ /// let abs_difference = (f.exp2() - 4.0).abs();
+ ///
+ /// assert!(abs_difference < 1e-10);
+ /// ```
+ fn exp2(self) -> Self;
+
+ /// Returns the natural logarithm of the number.
+ ///
+ /// # Panics
+ ///
+ /// If `self <= 0` and this type does not support a NaN representation, this function should panic.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ ///
+ /// let one = 1.0;
+ /// // e^1
+ /// let e = one.exp();
+ ///
+ /// // ln(e) - 1 == 0
+ /// let abs_difference = (e.ln() - 1.0).abs();
+ ///
+ /// assert!(abs_difference < 1e-10);
+ /// ```
+ fn ln(self) -> Self;
+
+ /// Returns the logarithm of the number with respect to an arbitrary base.
+ ///
+ /// # Panics
+ ///
+ /// If `self <= 0` and this type does not support a NaN representation, this function should panic.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ ///
+ /// let ten = 10.0;
+ /// let two = 2.0;
+ ///
+ /// // log10(10) - 1 == 0
+ /// let abs_difference_10 = (ten.log(10.0) - 1.0).abs();
+ ///
+ /// // log2(2) - 1 == 0
+ /// let abs_difference_2 = (two.log(2.0) - 1.0).abs();
+ ///
+ /// assert!(abs_difference_10 < 1e-10);
+ /// assert!(abs_difference_2 < 1e-10);
+ /// ```
+ fn log(self, base: Self) -> Self;
+
+ /// Returns the base 2 logarithm of the number.
+ ///
+ /// # Panics
+ ///
+ /// If `self <= 0` and this type does not support a NaN representation, this function should panic.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ ///
+ /// let two = 2.0;
+ ///
+ /// // log2(2) - 1 == 0
+ /// let abs_difference = (two.log2() - 1.0).abs();
+ ///
+ /// assert!(abs_difference < 1e-10);
+ /// ```
+ fn log2(self) -> Self;
+
+ /// Returns the base 10 logarithm of the number.
+ ///
+ /// # Panics
+ ///
+ /// If `self <= 0` and this type does not support a NaN representation, this function should panic.
+ ///
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ ///
+ /// let ten = 10.0;
+ ///
+ /// // log10(10) - 1 == 0
+ /// let abs_difference = (ten.log10() - 1.0).abs();
+ ///
+ /// assert!(abs_difference < 1e-10);
+ /// ```
+ fn log10(self) -> Self;
+
+ /// Converts radians to degrees.
+ ///
+ /// ```
+ /// use std::f64::consts;
+ ///
+ /// let angle = consts::PI;
+ ///
+ /// let abs_difference = (angle.to_degrees() - 180.0).abs();
+ ///
+ /// assert!(abs_difference < 1e-10);
+ /// ```
+ fn to_degrees(self) -> Self;
+
+ /// Converts degrees to radians.
+ ///
+ /// ```
+ /// use std::f64::consts;
+ ///
+ /// let angle = 180.0_f64;
+ ///
+ /// let abs_difference = (angle.to_radians() - consts::PI).abs();
+ ///
+ /// assert!(abs_difference < 1e-10);
+ /// ```
+ fn to_radians(self) -> Self;
+
+ /// Returns the maximum of the two numbers.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ ///
+ /// let x = 1.0;
+ /// let y = 2.0;
+ ///
+ /// assert_eq!(x.max(y), y);
+ /// ```
+ fn max(self, other: Self) -> Self;
+
+ /// Returns the minimum of the two numbers.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ ///
+ /// let x = 1.0;
+ /// let y = 2.0;
+ ///
+ /// assert_eq!(x.min(y), x);
+ /// ```
+ fn min(self, other: Self) -> Self;
+
+ /// The positive difference of two numbers.
+ ///
+ /// * If `self <= other`: `0:0`
+ /// * Else: `self - other`
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ ///
+ /// let x = 3.0;
+ /// let y = -3.0;
+ ///
+ /// let abs_difference_x = (x.abs_sub(1.0) - 2.0).abs();
+ /// let abs_difference_y = (y.abs_sub(1.0) - 0.0).abs();
+ ///
+ /// assert!(abs_difference_x < 1e-10);
+ /// assert!(abs_difference_y < 1e-10);
+ /// ```
+ fn abs_sub(self, other: Self) -> Self;
+
+ /// Take the cubic root of a number.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ ///
+ /// let x = 8.0;
+ ///
+ /// // x^(1/3) - 2 == 0
+ /// let abs_difference = (x.cbrt() - 2.0).abs();
+ ///
+ /// assert!(abs_difference < 1e-10);
+ /// ```
+ fn cbrt(self) -> Self;
+
+ /// Calculate the length of the hypotenuse of a right-angle triangle given
+ /// legs of length `x` and `y`.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ ///
+ /// let x = 2.0;
+ /// let y = 3.0;
+ ///
+ /// // sqrt(x^2 + y^2)
+ /// let abs_difference = (x.hypot(y) - (x.powi(2) + y.powi(2)).sqrt()).abs();
+ ///
+ /// assert!(abs_difference < 1e-10);
+ /// ```
+ fn hypot(self, other: Self) -> Self;
+
+ /// Computes the sine of a number (in radians).
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ /// use std::f64;
+ ///
+ /// let x = f64::consts::PI/2.0;
+ ///
+ /// let abs_difference = (x.sin() - 1.0).abs();
+ ///
+ /// assert!(abs_difference < 1e-10);
+ /// ```
+ fn sin(self) -> Self;
+
+ /// Computes the cosine of a number (in radians).
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ /// use std::f64;
+ ///
+ /// let x = 2.0*f64::consts::PI;
+ ///
+ /// let abs_difference = (x.cos() - 1.0).abs();
+ ///
+ /// assert!(abs_difference < 1e-10);
+ /// ```
+ fn cos(self) -> Self;
+
+ /// Computes the tangent of a number (in radians).
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ /// use std::f64;
+ ///
+ /// let x = f64::consts::PI/4.0;
+ /// let abs_difference = (x.tan() - 1.0).abs();
+ ///
+ /// assert!(abs_difference < 1e-14);
+ /// ```
+ fn tan(self) -> Self;
+
+ /// 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].
+ ///
+ /// # Panics
+ ///
+ /// If this type does not support a NaN representation, this function should panic
+ /// if the number is outside the range [-1, 1].
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ /// use std::f64;
+ ///
+ /// let f = f64::consts::PI / 2.0;
+ ///
+ /// // asin(sin(pi/2))
+ /// let abs_difference = (f.sin().asin() - f64::consts::PI / 2.0).abs();
+ ///
+ /// assert!(abs_difference < 1e-10);
+ /// ```
+ fn asin(self) -> Self;
+
+ /// 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].
+ ///
+ /// # Panics
+ ///
+ /// If this type does not support a NaN representation, this function should panic
+ /// if the number is outside the range [-1, 1].
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ /// use std::f64;
+ ///
+ /// let f = f64::consts::PI / 4.0;
+ ///
+ /// // acos(cos(pi/4))
+ /// let abs_difference = (f.cos().acos() - f64::consts::PI / 4.0).abs();
+ ///
+ /// assert!(abs_difference < 1e-10);
+ /// ```
+ fn acos(self) -> Self;
+
+ /// Computes the arctangent of a number. Return value is in radians in the
+ /// range [-pi/2, pi/2];
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ ///
+ /// let f = 1.0;
+ ///
+ /// // atan(tan(1))
+ /// let abs_difference = (f.tan().atan() - 1.0).abs();
+ ///
+ /// assert!(abs_difference < 1e-10);
+ /// ```
+ fn atan(self) -> Self;
+
+ /// Computes the four quadrant arctangent of `self` (`y`) and `other` (`x`).
+ ///
+ /// * `x = 0`, `y = 0`: `0`
+ /// * `x >= 0`: `arctan(y/x)` -> `[-pi/2, pi/2]`
+ /// * `y >= 0`: `arctan(y/x) + pi` -> `(pi/2, pi]`
+ /// * `y < 0`: `arctan(y/x) - pi` -> `(-pi, -pi/2)`
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ /// use std::f64;
+ ///
+ /// let pi = f64::consts::PI;
+ /// // All angles from horizontal right (+x)
+ /// // 45 deg counter-clockwise
+ /// let x1 = 3.0;
+ /// let y1 = -3.0;
+ ///
+ /// // 135 deg clockwise
+ /// let x2 = -3.0;
+ /// let y2 = 3.0;
+ ///
+ /// let abs_difference_1 = (y1.atan2(x1) - (-pi/4.0)).abs();
+ /// let abs_difference_2 = (y2.atan2(x2) - 3.0*pi/4.0).abs();
+ ///
+ /// assert!(abs_difference_1 < 1e-10);
+ /// assert!(abs_difference_2 < 1e-10);
+ /// ```
+ fn atan2(self, other: Self) -> Self;
+
+ /// Simultaneously computes the sine and cosine of the number, `x`. Returns
+ /// `(sin(x), cos(x))`.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ /// use std::f64;
+ ///
+ /// let x = f64::consts::PI/4.0;
+ /// let f = x.sin_cos();
+ ///
+ /// let abs_difference_0 = (f.0 - x.sin()).abs();
+ /// let abs_difference_1 = (f.1 - x.cos()).abs();
+ ///
+ /// assert!(abs_difference_0 < 1e-10);
+ /// assert!(abs_difference_0 < 1e-10);
+ /// ```
+ fn sin_cos(self) -> (Self, Self);
+
+ /// Returns `e^(self) - 1` in a way that is accurate even if the
+ /// number is close to zero.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ ///
+ /// let x = 7.0;
+ ///
+ /// // e^(ln(7)) - 1
+ /// let abs_difference = (x.ln().exp_m1() - 6.0).abs();
+ ///
+ /// assert!(abs_difference < 1e-10);
+ /// ```
+ fn exp_m1(self) -> Self;
+
+ /// Returns `ln(1+n)` (natural logarithm) more accurately than if
+ /// the operations were performed separately.
+ ///
+ /// # Panics
+ ///
+ /// If this type does not support a NaN representation, this function should panic
+ /// if `self-1 <= 0`.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ /// use std::f64;
+ ///
+ /// let x = f64::consts::E - 1.0;
+ ///
+ /// // ln(1 + (e - 1)) == ln(e) == 1
+ /// let abs_difference = (x.ln_1p() - 1.0).abs();
+ ///
+ /// assert!(abs_difference < 1e-10);
+ /// ```
+ fn ln_1p(self) -> Self;
+
+ /// Hyperbolic sine function.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ /// use std::f64;
+ ///
+ /// let e = f64::consts::E;
+ /// let x = 1.0;
+ ///
+ /// let f = x.sinh();
+ /// // Solving sinh() at 1 gives `(e^2-1)/(2e)`
+ /// let g = (e*e - 1.0)/(2.0*e);
+ /// let abs_difference = (f - g).abs();
+ ///
+ /// assert!(abs_difference < 1e-10);
+ /// ```
+ fn sinh(self) -> Self;
+
+ /// Hyperbolic cosine function.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ /// use std::f64;
+ ///
+ /// let e = f64::consts::E;
+ /// let x = 1.0;
+ /// let f = x.cosh();
+ /// // Solving cosh() at 1 gives this result
+ /// let g = (e*e + 1.0)/(2.0*e);
+ /// let abs_difference = (f - g).abs();
+ ///
+ /// // Same result
+ /// assert!(abs_difference < 1.0e-10);
+ /// ```
+ fn cosh(self) -> Self;
+
+ /// Hyperbolic tangent function.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ /// use std::f64;
+ ///
+ /// let e = f64::consts::E;
+ /// let x = 1.0;
+ ///
+ /// let f = x.tanh();
+ /// // Solving tanh() at 1 gives `(1 - e^(-2))/(1 + e^(-2))`
+ /// let g = (1.0 - e.powi(-2))/(1.0 + e.powi(-2));
+ /// let abs_difference = (f - g).abs();
+ ///
+ /// assert!(abs_difference < 1.0e-10);
+ /// ```
+ fn tanh(self) -> Self;
+
+ /// Inverse hyperbolic sine function.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ ///
+ /// let x = 1.0;
+ /// let f = x.sinh().asinh();
+ ///
+ /// let abs_difference = (f - x).abs();
+ ///
+ /// assert!(abs_difference < 1.0e-10);
+ /// ```
+ fn asinh(self) -> Self;
+
+ /// Inverse hyperbolic cosine function.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ ///
+ /// let x = 1.0;
+ /// let f = x.cosh().acosh();
+ ///
+ /// let abs_difference = (f - x).abs();
+ ///
+ /// assert!(abs_difference < 1.0e-10);
+ /// ```
+ fn acosh(self) -> Self;
+
+ /// Inverse hyperbolic tangent function.
+ ///
+ /// ```
+ /// use num_traits::real::Real;
+ /// use std::f64;
+ ///
+ /// let e = f64::consts::E;
+ /// let f = e.tanh().atanh();
+ ///
+ /// let abs_difference = (f - e).abs();
+ ///
+ /// assert!(abs_difference < 1.0e-10);
+ /// ```
+ fn atanh(self) -> Self;
+}
+
+impl<T: Float> Real for T {
+ fn min_value() -> Self {
+ Self::min_value()
+ }
+ fn min_positive_value() -> Self {
+ Self::min_positive_value()
+ }
+ fn epsilon() -> Self {
+ Self::epsilon()
+ }
+ fn max_value() -> Self {
+ Self::max_value()
+ }
+ fn floor(self) -> Self {
+ self.floor()
+ }
+ fn ceil(self) -> Self {
+ self.ceil()
+ }
+ fn round(self) -> Self {
+ self.round()
+ }
+ fn trunc(self) -> Self {
+ self.trunc()
+ }
+ fn fract(self) -> Self {
+ self.fract()
+ }
+ fn abs(self) -> Self {
+ self.abs()
+ }
+ fn signum(self) -> Self {
+ self.signum()
+ }
+ fn is_sign_positive(self) -> bool {
+ self.is_sign_positive()
+ }
+ fn is_sign_negative(self) -> bool {
+ self.is_sign_negative()
+ }
+ fn mul_add(self, a: Self, b: Self) -> Self {
+ self.mul_add(a, b)
+ }
+ fn recip(self) -> Self {
+ self.recip()
+ }
+ fn powi(self, n: i32) -> Self {
+ self.powi(n)
+ }
+ fn powf(self, n: Self) -> Self {
+ self.powf(n)
+ }
+ fn sqrt(self) -> Self {
+ self.sqrt()
+ }
+ fn exp(self) -> Self {
+ self.exp()
+ }
+ fn exp2(self) -> Self {
+ self.exp2()
+ }
+ fn ln(self) -> Self {
+ self.ln()
+ }
+ fn log(self, base: Self) -> Self {
+ self.log(base)
+ }
+ fn log2(self) -> Self {
+ self.log2()
+ }
+ fn log10(self) -> Self {
+ self.log10()
+ }
+ fn to_degrees(self) -> Self {
+ self.to_degrees()
+ }
+ fn to_radians(self) -> Self {
+ self.to_radians()
+ }
+ fn max(self, other: Self) -> Self {
+ self.max(other)
+ }
+ fn min(self, other: Self) -> Self {
+ self.min(other)
+ }
+ fn abs_sub(self, other: Self) -> Self {
+ self.abs_sub(other)
+ }
+ fn cbrt(self) -> Self {
+ self.cbrt()
+ }
+ fn hypot(self, other: Self) -> Self {
+ self.hypot(other)
+ }
+ fn sin(self) -> Self {
+ self.sin()
+ }
+ fn cos(self) -> Self {
+ self.cos()
+ }
+ fn tan(self) -> Self {
+ self.tan()
+ }
+ fn asin(self) -> Self {
+ self.asin()
+ }
+ fn acos(self) -> Self {
+ self.acos()
+ }
+ fn atan(self) -> Self {
+ self.atan()
+ }
+ fn atan2(self, other: Self) -> Self {
+ self.atan2(other)
+ }
+ fn sin_cos(self) -> (Self, Self) {
+ self.sin_cos()
+ }
+ fn exp_m1(self) -> Self {
+ self.exp_m1()
+ }
+ fn ln_1p(self) -> Self {
+ self.ln_1p()
+ }
+ fn sinh(self) -> Self {
+ self.sinh()
+ }
+ fn cosh(self) -> Self {
+ self.cosh()
+ }
+ fn tanh(self) -> Self {
+ self.tanh()
+ }
+ fn asinh(self) -> Self {
+ self.asinh()
+ }
+ fn acosh(self) -> Self {
+ self.acosh()
+ }
+ fn atanh(self) -> Self {
+ self.atanh()
+ }
+}
--- a/third_party/rust/num-traits/src/sign.rs
+++ b/third_party/rust/num-traits/src/sign.rs
@@ -1,11 +1,11 @@
-use std::ops::Neg;
-use std::{f32, f64};
-use std::num::Wrapping;
+use core::ops::Neg;
+use core::{f32, f64};
+use core::num::Wrapping;
use Num;
/// Useful functions for signed numbers (i.e. numbers that can be negative).
pub trait Signed: Sized + Num + Neg<Output = Self> {
/// Computes the absolute value.
///
/// For `f32` and `f64`, `NaN` will be returned if the number is `NaN`.
@@ -98,37 +98,69 @@ impl<T: Signed> Signed for Wrapping<T> w
fn is_negative(&self) -> bool { self.0.is_negative() }
}
macro_rules! signed_float_impl {
($t:ty, $nan:expr, $inf:expr, $neg_inf:expr) => {
impl Signed for $t {
/// Computes the absolute value. Returns `NAN` if the number is `NAN`.
#[inline]
+ #[cfg(feature = "std")]
fn abs(&self) -> $t {
- <$t>::abs(*self)
+ (*self).abs()
+ }
+
+ /// Computes the absolute value. Returns `NAN` if the number is `NAN`.
+ #[inline]
+ #[cfg(not(feature = "std"))]
+ fn abs(&self) -> $t {
+ if self.is_positive() {
+ *self
+ } else if self.is_negative() {
+ -*self
+ } else {
+ $nan
+ }
}
/// The positive difference of two numbers. Returns `0.0` if the number is
/// less than or equal to `other`, otherwise the difference between`self`
/// and `other` is returned.
#[inline]
- #[allow(deprecated)]
fn abs_sub(&self, other: &$t) -> $t {
- <$t>::abs_sub(*self, *other)
+ if *self <= *other { 0. } else { *self - *other }
}
/// # Returns
///
/// - `1.0` if the number is positive, `+0.0` or `INFINITY`
/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY`
/// - `NAN` if the number is NaN
#[inline]
+ #[cfg(feature = "std")]
fn signum(&self) -> $t {
- <$t>::signum(*self)
+ use Float;
+ Float::signum(*self)
+ }
+
+ /// # Returns
+ ///
+ /// - `1.0` if the number is positive, `+0.0` or `INFINITY`
+ /// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY`
+ /// - `NAN` if the number is NaN
+ #[inline]
+ #[cfg(not(feature = "std"))]
+ fn signum(&self) -> $t {
+ if self.is_positive() {
+ 1.0
+ } else if self.is_negative() {
+ -1.0
+ } else {
+ $nan
+ }
}
/// Returns `true` if the number is positive, including `+0.0` and `INFINITY`
#[inline]
fn is_positive(&self) -> bool { *self > 0.0 || (1.0 / *self) == $inf }
/// Returns `true` if the number is negative, including `-0.0` and `NEG_INFINITY`
#[inline]