├── .gitmodules ├── .gitignore ├── Cargo.toml ├── .editorconfig ├── dectest ├── Cargo.toml └── src │ ├── lib.rs │ ├── lex.rs │ ├── main.rs │ └── backend.rs ├── systest ├── Cargo.toml ├── src │ └── main.rs ├── extra.h └── build.rs ├── decnumber-sys ├── patch │ ├── 03-float-signed.patch │ ├── 02-alignment.patch │ └── 01-unused-comma-expr.patch ├── Cargo.toml ├── CHANGELOG.md ├── LICENSE ├── tests │ └── basic.rs ├── build.rs └── decnumber │ ├── ICU-license.html │ ├── decPacked.h │ ├── readme.txt │ ├── decSingle.c │ ├── decimal32.h │ ├── decimal128.h │ ├── decimal64.h │ ├── decSingle.h │ └── decQuad.c ├── RELEASING.md ├── dec ├── src │ ├── tests.rs │ ├── error.rs │ ├── lib.rs │ └── conv.rs ├── Cargo.toml ├── tests │ └── serde.rs └── benches │ └── dec.rs ├── README.md ├── testdata ├── decSingle.decTest ├── decDouble.decTest ├── decQuad.decTest ├── testall.decTest ├── copy.decTest ├── copyabs.decTest ├── ddCopy.decTest ├── copynegate.decTest ├── ddCopyAbs.decTest ├── ddPlus.decTest ├── ddMinus.decTest ├── ddClass.decTest ├── ddCopyNegate.decTest ├── dqClass.decTest ├── dqCopy.decTest ├── dqCopyAbs.decTest ├── dqPlus.decTest ├── dqMinus.decTest ├── dqCopyNegate.decTest ├── ddAbs.decTest ├── dqAbs.decTest ├── trim.decTest ├── class.decTest ├── ddLogB.decTest ├── dqLogB.decTest ├── abs.decTest └── ddNextPlus.decTest ├── .github └── workflows │ └── ci.yml └── update.sh /.gitmodules: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Cargo.lock 2 | target 3 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = [ 3 | "dec", 4 | "decnumber-sys", 5 | "dectest", 6 | "systest", 7 | ] 8 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | end_of_line = lf 3 | insert_final_newline = true 4 | indent_style = space 5 | indent_size = 4 6 | 7 | [*.yml] 8 | indent_size = 2 9 | 10 | [*.patch] 11 | trim_trailing_whitespace = false 12 | -------------------------------------------------------------------------------- /dectest/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "dectest" 3 | authors = ["Materialize, Inc."] 4 | description = "Decimal test driver." 5 | version = "0.0.0" 6 | edition = "2018" 7 | publish = false 8 | 9 | [dependencies] 10 | dec = { path = "../dec" } 11 | hex = "0.4.2" 12 | -------------------------------------------------------------------------------- /systest/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "systest" 3 | description = "ctest generator for decnumber-sys" 4 | version = "0.0.0" 5 | edition = "2018" 6 | publish = false 7 | 8 | [dependencies] 9 | decnumber-sys = { path = "../decnumber-sys" } 10 | libc = "0.2.68" 11 | 12 | [build-dependencies] 13 | ctest = "0.4" 14 | -------------------------------------------------------------------------------- /decnumber-sys/patch/03-float-signed.patch: -------------------------------------------------------------------------------- 1 | See: http://speleotrove.com/decimal/decnumerr.html 2 | 3 | diff --git a/decBasic.c b/decBasic.c 4 | index 56396f8..ac3fcf8 100644 5 | --- a/decBasic.c 6 | +++ b/decBasic.c 7 | @@ -2443,7 +2443,7 @@ uInt decFloatIsSignalling(const decFloat *df) { 8 | return DFISSNAN(df); 9 | } 10 | uInt decFloatIsSigned(const decFloat *df) { 11 | - return DFISSIGNED(df); 12 | + return DFISSIGNED(df)!=0; 13 | } 14 | uInt decFloatIsSubnormal(const decFloat *df) { 15 | if (DFISSPECIAL(df)) return 0; 16 | -------------------------------------------------------------------------------- /decnumber-sys/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "decnumber-sys" 3 | authors = ["Materialize, Inc."] 4 | readme = "../README.md" 5 | description = "Low-level bindings for libdecnumber." 6 | documentation = "https://docs.rs/decnumber-sys" 7 | repository = "https://github.com/MaterializeInc/rust-decnumber" 8 | license = "ICU" 9 | categories = ["external-ffi-bindings"] 10 | version = "0.1.6" 11 | edition = "2018" 12 | links = "decnumber" 13 | 14 | [dependencies] 15 | libc = "0.2.82" 16 | 17 | [dev-dependencies] 18 | c_str_macro = "1.0.2" 19 | version-sync = "0.9" 20 | 21 | [build-dependencies] 22 | cc = "1.0.50" 23 | -------------------------------------------------------------------------------- /systest/src/main.rs: -------------------------------------------------------------------------------- 1 | // Copyright Materialize, Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License in the LICENSE file at the 6 | // root of this repository, or online at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | use decnumber_sys::*; 17 | 18 | include!(concat!(env!("OUT_DIR"), "/all.rs")); 19 | -------------------------------------------------------------------------------- /systest/extra.h: -------------------------------------------------------------------------------- 1 | // Copyright Materialize, Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License in the LICENSE file at the 6 | // root of this repository, or online at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | // Extra headers for ctest to make it aware of some variables defined in 17 | // header files. 18 | 19 | extern const uint8_t BIN2CHAR[4001]; 20 | -------------------------------------------------------------------------------- /RELEASING.md: -------------------------------------------------------------------------------- 1 | # Release checklist 2 | 3 | * Update changelog(s). 4 | 5 | * Update versions in `Cargo.toml`(s). 6 | 7 | * Update versions in README. 8 | 9 | * Commit changes and merge to master. 10 | 11 | * Ensure tests have passed. 12 | 13 | * If releasing dec: 14 | 15 | ``` 16 | git tag -am "dec $VERSION" dec-$VERSION 17 | ``` 18 | 19 | * If releasing dec-sys: 20 | 21 | ``` 22 | git tag -am "decnumber-sys $VERSION" decnumber-sys-$VERSION 23 | ``` 24 | 25 | * Push tags: 26 | 27 | ``` 28 | git push --tags 29 | ``` 30 | 31 | * Create a new release on crates.io: 32 | 33 | ``` 34 | (cd dec && cargo publish) 35 | (cd decnumber-sys && cargo publish) 36 | ``` 37 | 38 | # Release permissions 39 | 40 | In order to successfully complete the `cargo publish` steps you must be a 41 | member of the "Crate owners" Github team and use an appropriate token through 42 | `cargo login`. 43 | -------------------------------------------------------------------------------- /dec/src/tests.rs: -------------------------------------------------------------------------------- 1 | // Copyright Materialize, Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License in the LICENSE file at the 6 | // root of this repository, or online at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | fn test_private_constants() { 17 | assert_eq!(Decimal64::TWO_POW_32.to_string(), "4294967296"); 18 | assert_eq!(Decimal128::TWO_POW_32.to_string(), "4294967296"); 19 | } 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rust-dec 2 | 3 | [libdecnumber] bindings for the Rust programming language. 4 | 5 | ## dec [![crates.io](https://img.shields.io/crates/v/dec.svg)](https://crates.io/crates/dec) 6 | 7 | A decimal arithmetic library providing high-level, safe bindings to 8 | libdecnumber. 9 | 10 | ``` 11 | # Cargo.toml 12 | [dependencies] 13 | dec = "0.4.11" 14 | ``` 15 | 16 | **[View documentation.](https://docs.rs/dec/0.4.9/)** 17 | 18 | ## decnumber-sys [![crates.io](https://img.shields.io/crates/v/decnumber-sys.svg)](https://crates.io/crates/decnumber-sys) 19 | 20 | Low-level bindings to libdecnumber. 21 | 22 | ``` 23 | # Cargo.toml 24 | [dependencies] 25 | decnumber-sys = "0.1.6" 26 | ``` 27 | 28 | **[View documentation.](https://docs.rs/decnumber-sys/0.1.6/)** 29 | 30 | [libdecnumber]: http://speleotrove.com/decimal/decnumber.html 31 | 32 | ## Releasing 33 | 34 | See `RELEASING.md` for instruction on how to release these crates. 35 | -------------------------------------------------------------------------------- /dectest/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright Materialize, Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License in the LICENSE file at the 6 | // root of this repository, or online at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //! Test runner for the General Decimal Arithmetic test cases. 17 | //! 18 | //! See for details. 19 | 20 | pub mod ast; 21 | pub mod backend; 22 | pub mod parse; 23 | pub mod run; 24 | 25 | mod lex; 26 | -------------------------------------------------------------------------------- /dec/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "dec" 3 | authors = ["Materialize, Inc."] 4 | readme = "../README.md" 5 | description = "A decimal arithmetic library providing high-level, safe bindings to libdecnumber." 6 | documentation = "https://docs.rs/dec" 7 | repository = "https://github.com/MaterializeInc/rust-decnumber" 8 | license = "Apache-2.0" 9 | categories = ["api-bindings"] 10 | keywords = ["decimal", "decnumber"] 11 | version = "0.4.11" 12 | edition = "2018" 13 | 14 | [dependencies] 15 | decnumber-sys = { version = "0.1.5", path = "../decnumber-sys" } 16 | libc = "0.2.82" 17 | num-traits = { version = "0.2.14", optional = true } 18 | paste = "1.0.11" 19 | serde = { version = "1.0.124", features = ["derive"], optional = true } 20 | static_assertions = "1.1.0" 21 | 22 | [dev-dependencies] 23 | criterion = "0.3.0" 24 | rand = "0.7.3" 25 | serde_json = "1.0.89" 26 | serde_test = "1.0.117" 27 | 28 | [package.metadata.docs.rs] 29 | all-features = true 30 | rustdoc-args = ["--cfg", "docsrs"] 31 | 32 | [[bench]] 33 | name = "dec" 34 | harness = false 35 | 36 | [[test]] 37 | name = "serde" 38 | required-features = ["serde"] 39 | -------------------------------------------------------------------------------- /decnumber-sys/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this crate will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog], and this crate adheres to [Semantic 6 | Versioning]. 7 | 8 | ## 0.1.6 - 2023-02-02 9 | 10 | * Fix potential memory unsafety ([#80]). Thanks, [@icmccorm] and [@def-]! 11 | 12 | ## 0.1.5 - 2020-03-10 13 | 14 | * Expose the lookup table for converting binary numbers 0-999 to their 15 | 3-character representations, `BIN2CHAR`. 16 | 17 | ## 0.1.4 - 2020-02-25 18 | 19 | * Expose lookup tables for converting DPD to binary: `DPD2BIN`, `DPD2BINK`, 20 | `DPD2BINM`, `DECCOMBMSD`. 21 | 22 | ## 0.1.3 - 2020-02-03 23 | 24 | * Import a patch that corrects `decDoubleIsSigned` and `decQuadIsSigned`, which 25 | were previously inverted from their documented behavior. 26 | 27 | This patch comes from the [libdecnumber errata][errata]. 28 | 29 | ## 0.1.2 - 2020-02-01 30 | 31 | * Correct documentation links in README, again. 32 | 33 | ## 0.1.1 - 2020-02-01 34 | 35 | * Correct documentation links in README. 36 | 37 | ## 0.1.0 - 2020-01-31 38 | 39 | Initial release. 40 | 41 | [#80]: https://github.com/MaterializeInc/rust-dec/issues/80 42 | [@icmccorm]: https://github.com/icmccorm 43 | [@def-]: https://github.com/def- 44 | [Keep a Changelog]: https://keepachangelog.com/en/1.0.0/ 45 | [Semantic Versioning]: https://semver.org/spec/v2.0.0.html 46 | [errata]: http://speleotrove.com/decimal/decnumerr.html 47 | -------------------------------------------------------------------------------- /testdata/decSingle.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- decSingle.decTest -- run all decSingle decimal arithmetic tests -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | -- decSingle tests 22 | dectest: dsBase 23 | dectest: dsEncode 24 | 25 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | on: [push, pull_request] 3 | 4 | jobs: 5 | test: 6 | name: test 7 | runs-on: ${{ matrix.os }} 8 | strategy: 9 | fail-fast: false 10 | matrix: 11 | include: 12 | - build: ubuntu 13 | os: ubuntu-latest 14 | rust: stable 15 | - build: macos 16 | os: macos-latest 17 | rust: stable 18 | steps: 19 | - uses: actions/checkout@v1 20 | with: 21 | submodules: true 22 | - name: Install Rust (rustup) 23 | run: rustup update ${{ matrix.rust }} --no-self-update && rustup default ${{ matrix.rust }} 24 | - run: cd decnumber-sys && cargo test 25 | - run: cd systest && cargo run 26 | - run: cd dectest && cargo run -- -b decimal32 ../testdata/decSingle.decTest 27 | - run: cd dectest && cargo run -- -b decimal64 ../testdata/decDouble.decTest 28 | - run: cd dectest && cargo run -- -b decimal128 ../testdata/decQuad.decTest 29 | - run: cd dectest && cargo run -- -b decimal ../testdata/testall.decTest 30 | - run: cargo test 31 | - run: cargo test --features=serde 32 | - run: cargo test --features=num-traits 33 | 34 | lint: 35 | name: lint 36 | runs-on: ubuntu-latest 37 | steps: 38 | - uses: actions/checkout@v1 39 | with: 40 | submodules: true 41 | - name: Install Rust 42 | run: rustup update stable && rustup default stable && rustup component add rustfmt 43 | - run: cargo fmt -- --check 44 | -------------------------------------------------------------------------------- /update.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | cd "$(dirname "$0")" 6 | 7 | curl -fsSL http://speleotrove.com/decimal/decNumber-icu-368.zip > decnumber.zip 8 | 9 | rm -rf decnumber-sys/decnumber 10 | unzip decnumber.zip 11 | mv decNumber decnumber-sys/decnumber 12 | rm decnumber-sys/decnumber/example{1,2,3,4,5,6,7,8}.c decnumber-sys/decnumber/decnumber.pdf 13 | rm decnumber.zip 14 | 15 | ( 16 | cd decnumber-sys/decnumber 17 | 18 | for f in *; do 19 | dos2unix "$f" 20 | done 21 | 22 | for p in ../patch/*; do 23 | patch -sp1 -i "$p" 24 | done 25 | find . -name '*.orig' -delete 26 | ) 27 | 28 | curl -fsSL http://speleotrove.com/decimal/dectest.zip > dectest.zip 29 | rm -rf testdata 30 | mkdir testdata 31 | ( 32 | cd testdata 33 | 34 | unzip ../dectest.zip 35 | 36 | for f in *; do 37 | dos2unix "$f" 38 | done 39 | 40 | patch -p1 <33-digit boundary tests 57 | dectest: randombound32 58 | EOF 59 | ) 60 | rm dectest.zip 61 | -------------------------------------------------------------------------------- /dectest/src/lex.rs: -------------------------------------------------------------------------------- 1 | // Copyright Materialize, Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License in the LICENSE file at the 6 | // root of this repository, or online at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | pub struct LexBuf<'a> { 17 | pub s: &'a str, 18 | } 19 | 20 | impl<'a> LexBuf<'a> { 21 | pub fn new(s: &'a str) -> LexBuf { 22 | LexBuf { s } 23 | } 24 | 25 | pub fn peek(&self) -> Option { 26 | self.s.chars().next() 27 | } 28 | 29 | pub fn consume(&mut self, s: &str) -> bool { 30 | let self_bytes = self.s.as_bytes(); 31 | let b = s.as_bytes(); 32 | if self_bytes.len() >= b.len() && self_bytes[..b.len()] == *b { 33 | self.s = &self.s[b.len()..]; 34 | true 35 | } else { 36 | false 37 | } 38 | } 39 | } 40 | 41 | impl<'a> Iterator for LexBuf<'a> { 42 | type Item = char; 43 | 44 | fn next(&mut self) -> Option { 45 | let ch = self.peek(); 46 | if let Some(ch) = ch { 47 | self.s = &self.s[ch.len_utf8()..]; 48 | } 49 | ch 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /systest/build.rs: -------------------------------------------------------------------------------- 1 | // Copyright Materialize, Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License in the LICENSE file at the 6 | // root of this repository, or online at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | use std::env; 17 | use std::path::PathBuf; 18 | 19 | fn main() { 20 | let root = PathBuf::from(env::var_os("DEP_DECNUMBER_ROOT").unwrap()); 21 | 22 | ctest::TestGenerator::new() 23 | .include(".") 24 | .include(root.join("include")) 25 | .header("decimal128.h") 26 | .header("decimal64.h") 27 | .header("decimal32.h") 28 | .header("decContext.h") 29 | .header("decNumber.h") 30 | .header("decSingle.h") 31 | .header("decDouble.h") 32 | .header("decQuad.h") 33 | .header("decPacked.h") 34 | .header("decNumberLocal.h") 35 | .header("extra.h") 36 | .type_name(|ty, _is_struct, _is_union| match ty { 37 | "rounding" => "enum rounding".into(), 38 | "decClass" => "enum decClass".into(), 39 | _ => ty.to_string(), 40 | }) 41 | .generate("../decnumber-sys/src/lib.rs", "all.rs"); 42 | } 43 | -------------------------------------------------------------------------------- /decnumber-sys/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright Materialize, Inc. All rights reserved. 2 | 3 | Copyright (c) 1995-2005 International Business Machines Corporation and others 4 | All rights reserved. 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, and/or sell copies of the Software, and to permit persons 11 | to whom the Software is furnished to do so, provided that the above 12 | copyright notice(s) and this permission notice appear in all copies of 13 | the Software and that both the above copyright notice(s) and this 14 | permission notice appear in supporting documentation. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 19 | OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 20 | HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL 21 | INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING 22 | FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 23 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 24 | WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 25 | 26 | Except as contained in this notice, the name of a copyright holder 27 | shall not be used in advertising or otherwise to promote the sale, use 28 | or other dealings in this Software without prior written authorization 29 | of the copyright holder. 30 | -------------------------------------------------------------------------------- /decnumber-sys/patch/02-alignment.patch: -------------------------------------------------------------------------------- 1 | diff --git a/decimal128.h b/decimal128.h 2 | index df72acf..8f6b315 100644 3 | --- a/decimal128.h 4 | +++ b/decimal128.h 5 | @@ -49,8 +49,13 @@ 6 | #endif 7 | 8 | /* Decimal 128-bit type, accessible by bytes */ 9 | - typedef struct { 10 | + typedef union { 11 | uint8_t bytes[DECIMAL128_Bytes]; /* decimal128: 1, 5, 12, 110 bits*/ 12 | + uint16_t shorts[DECIMAL128_Bytes/2]; 13 | + uint32_t words[DECIMAL128_Bytes/4]; 14 | + #if DECUSE64 15 | + uint64_t longs[DECIMAL128_Bytes/8]; 16 | + #endif 17 | } decimal128; 18 | 19 | /* special values [top byte excluding sign bit; last two bits are */ 20 | diff --git a/decimal32.h b/decimal32.h 21 | index faaf9a9..233f7a8 100644 22 | --- a/decimal32.h 23 | +++ b/decimal32.h 24 | @@ -49,8 +49,10 @@ 25 | #endif 26 | 27 | /* Decimal 32-bit type, accessible by bytes */ 28 | - typedef struct { 29 | + typedef union { 30 | uint8_t bytes[DECIMAL32_Bytes]; /* decimal32: 1, 5, 6, 20 bits*/ 31 | + uint16_t shorts[DECIMAL32_Bytes/2]; 32 | + uint32_t words[DECIMAL32_Bytes/4]; 33 | } decimal32; 34 | 35 | /* special values [top byte excluding sign bit; last two bits are */ 36 | diff --git a/decimal64.h b/decimal64.h 37 | index d2782a3..8b5308c 100644 38 | --- a/decimal64.h 39 | +++ b/decimal64.h 40 | @@ -51,8 +51,13 @@ 41 | #endif 42 | 43 | /* Decimal 64-bit type, accessible by bytes */ 44 | - typedef struct { 45 | + typedef union { 46 | uint8_t bytes[DECIMAL64_Bytes]; /* decimal64: 1, 5, 8, 50 bits*/ 47 | + uint16_t shorts[DECIMAL64_Bytes/2]; 48 | + uint32_t words[DECIMAL64_Bytes/4]; 49 | + #if DECUSE64 50 | + uint64_t longs[DECIMAL64_Bytes/8]; 51 | + #endif 52 | } decimal64; 53 | 54 | /* special values [top byte excluding sign bit; last two bits are */ 55 | -------------------------------------------------------------------------------- /decnumber-sys/tests/basic.rs: -------------------------------------------------------------------------------- 1 | use std::ffi::CStr; 2 | use std::mem::MaybeUninit; 3 | 4 | use c_str_macro::c_str; 5 | use libc::c_char; 6 | 7 | use decnumber_sys::{decContext, decNumber, DEC_INIT_BASE}; 8 | 9 | #[test] 10 | fn simple_addition() { 11 | let mut ctx = MaybeUninit::::uninit(); 12 | let mut ctx = unsafe { 13 | decnumber_sys::decContextDefault(ctx.as_mut_ptr(), DEC_INIT_BASE); 14 | ctx.assume_init() 15 | }; 16 | ctx.traps = 0; 17 | ctx.digits = 3; 18 | 19 | let mut a = decNumber { 20 | digits: 1, 21 | exponent: 0, 22 | bits: 0, 23 | lsu: [0; 12], 24 | }; 25 | let mut b = decNumber { 26 | digits: 1, 27 | exponent: 0, 28 | bits: 0, 29 | lsu: [0; 12], 30 | }; 31 | 32 | unsafe { 33 | decnumber_sys::decNumberFromString( 34 | &mut a as *mut decNumber, 35 | c_str!("1.23").as_ptr(), 36 | &mut ctx, 37 | ); 38 | decnumber_sys::decNumberFromString( 39 | &mut b as *mut decNumber, 40 | c_str!("4.71").as_ptr(), 41 | &mut ctx, 42 | ); 43 | } 44 | let a_as_ptr = &mut a as *mut decNumber; 45 | unsafe { 46 | decnumber_sys::decNumberAdd(a_as_ptr, a_as_ptr, &mut b, &mut ctx); 47 | } 48 | 49 | let mut buf = vec![0_u8; 5]; 50 | unsafe { 51 | decnumber_sys::decNumberToString(&mut a, buf.as_mut_ptr() as *mut c_char); 52 | } 53 | let s = CStr::from_bytes_with_nul(&*buf).unwrap().to_str().unwrap(); 54 | assert_eq!(s, "5.94"); 55 | } 56 | 57 | #[test] 58 | fn endianness() { 59 | let mut ctx = MaybeUninit::::uninit(); 60 | unsafe { 61 | decnumber_sys::decContextDefault(ctx.as_mut_ptr(), DEC_INIT_BASE); 62 | assert_eq!(decnumber_sys::decContextTestEndian(0), 0); 63 | }; 64 | } 65 | -------------------------------------------------------------------------------- /decnumber-sys/build.rs: -------------------------------------------------------------------------------- 1 | // Copyright Materialize, Inc. All rights reserved. 2 | // 3 | // This software is made available under the terms of the 4 | // ICU license -- ICU 1.8.1 and later. 5 | 6 | use std::env; 7 | use std::fs; 8 | use std::path::{Path, PathBuf}; 9 | 10 | fn main() { 11 | let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); 12 | 13 | let declitend = if cfg!(target_endian = "little") { 14 | "1" 15 | } else { 16 | "0" 17 | }; 18 | cc::Build::new() 19 | .define("DECLITEND", Some(declitend)) 20 | .file("decnumber/decimal128.c") 21 | .file("decnumber/decimal64.c") 22 | .file("decnumber/decimal32.c") 23 | .file("decnumber/decContext.c") 24 | .file("decnumber/decNumber.c") 25 | .file("decnumber/decSingle.c") 26 | .file("decnumber/decDouble.c") 27 | .file("decnumber/decQuad.c") 28 | .file("decnumber/decPacked.c") 29 | .out_dir(out_dir.join("lib")) 30 | .compile("decnumber"); 31 | 32 | let include_dir = out_dir.join("include"); 33 | fs::create_dir_all(&include_dir).unwrap_or_else(|e| { 34 | panic!( 35 | "failed to create include directory {}: {}", 36 | include_dir.display(), 37 | e 38 | ) 39 | }); 40 | for header in &[ 41 | "decimal128.h", 42 | "decimal64.h", 43 | "decimal32.h", 44 | "decContext.h", 45 | "decNumber.h", 46 | "decSingle.h", 47 | "decDouble.h", 48 | "decQuad.h", 49 | "decPacked.h", 50 | "decDPD.h", 51 | "decNumberLocal.h", 52 | ] { 53 | let src = Path::new("decnumber").join(header); 54 | let dst = out_dir.join("include").join(header); 55 | fs::copy(&src, &dst).unwrap_or_else(|e| { 56 | panic!( 57 | "failed to copy {} to include directory: {}", 58 | src.display(), 59 | e 60 | ) 61 | }); 62 | } 63 | 64 | println!("cargo:root={}", out_dir.display()); 65 | } 66 | -------------------------------------------------------------------------------- /decnumber-sys/decnumber/ICU-license.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ICU License - ICU 1.8.1 and later 6 | 7 | 8 | 9 |

ICU License - ICU 1.8.1 and later

10 |
11 | COPYRIGHT AND PERMISSION NOTICE
12 | 
13 | Copyright (c) 1995-2005 International Business Machines Corporation and others
14 | All rights reserved.
15 | 
16 | Permission is hereby granted, free of charge, to any person obtaining a
17 | copy of this software and associated documentation files (the
18 | "Software"), to deal in the Software without restriction, including
19 | without limitation the rights to use, copy, modify, merge, publish,
20 | distribute, and/or sell copies of the Software, and to permit persons
21 | to whom the Software is furnished to do so, provided that the above
22 | copyright notice(s) and this permission notice appear in all copies of
23 | the Software and that both the above copyright notice(s) and this
24 | permission notice appear in supporting documentation.
25 | 
26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
29 | OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
30 | HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
31 | INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
32 | FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
33 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
34 | WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
35 | 
36 | Except as contained in this notice, the name of a copyright holder
37 | shall not be used in advertising or otherwise to promote the sale, use
38 | or other dealings in this Software without prior written authorization
39 | of the copyright holder.
40 | 
41 | --------------------------------------------------------------------------------
42 | All trademarks and registered trademarks mentioned herein are the property of their respective owners.
43 | 
44 | 45 | 46 | -------------------------------------------------------------------------------- /decnumber-sys/patch/01-unused-comma-expr.patch: -------------------------------------------------------------------------------- 1 | From 789eadcd54ffe62037461a4a22c2737ad9cbd01e Mon Sep 17 00:00:00 2001 2 | From: Marek Polacek 3 | Date: Thu, 23 Jan 2014 19:04:29 +0000 4 | Subject: [PATCH] re PR c/59871 (No unused value warning for comma expression) 5 | 6 | PR c/59871 7 | c/ 8 | * c-typeck.c (build_compound_expr): Warn even for right-hand operand 9 | of a comma expression. 10 | (emit_side_effect_warnings): Likewise. 11 | libdecnumber/ 12 | * decNumberLocal.h (UBFROMUS, UBFROMUI): Remove last argument. 13 | testsuite/ 14 | * gcc.dg/20020220-2.c: Adjust dg-warning message. 15 | * gcc.dg/pr59871.c: New test. 16 | 17 | From-SVN: r207002 18 | --- 19 | gcc/c/ChangeLog | 7 +++++++ 20 | gcc/c/c-typeck.c | 34 +++++++++++++++++++++++++++++++ 21 | gcc/testsuite/ChangeLog | 6 ++++++ 22 | gcc/testsuite/gcc.dg/20020220-2.c | 4 ++-- 23 | gcc/testsuite/gcc.dg/pr59871.c | 22 ++++++++++++++++++++ 24 | libdecnumber/ChangeLog | 5 +++++ 25 | libdecnumber/decNumberLocal.h | 7 +++---- 26 | 7 files changed, 79 insertions(+), 6 deletions(-) 27 | create mode 100644 gcc/testsuite/gcc.dg/pr59871.c 28 | 29 | diff --git a/decNumberLocal.h b/decNumberLocal.h 30 | index 94e7f7f9b1f7..4936231f2a2b 100644 31 | --- a/decNumberLocal.h 32 | +++ b/decNumberLocal.h 33 | @@ -153,10 +153,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 34 | #define UBTOUI(b) (memcpy((void *)&uiwork, b, 4), uiwork) 35 | 36 | /* Store a uInt, etc., into bytes starting at a char* or uByte*. */ 37 | - /* Returns i, evaluated, for convenience; has to use uiwork because */ 38 | - /* i may be an expression. */ 39 | - #define UBFROMUS(b, i) (uswork=(i), memcpy(b, (void *)&uswork, 2), uswork) 40 | - #define UBFROMUI(b, i) (uiwork=(i), memcpy(b, (void *)&uiwork, 4), uiwork) 41 | + /* Has to use uiwork because i may be an expression. */ 42 | + #define UBFROMUS(b, i) (uswork=(i), memcpy(b, (void *)&uswork, 2)) 43 | + #define UBFROMUI(b, i) (uiwork=(i), memcpy(b, (void *)&uiwork, 4)) 44 | 45 | /* X10 and X100 -- multiply integer i by 10 or 100 */ 46 | /* [shifts are usually faster than multiply; could be conditional] */ 47 | -------------------------------------------------------------------------------- /testdata/decDouble.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- decDouble.decTest -- run all decDouble decimal arithmetic tests -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | -- decDouble tests 22 | dectest: ddAbs 23 | dectest: ddAdd 24 | dectest: ddAnd 25 | dectest: ddBase 26 | dectest: ddCanonical 27 | dectest: ddClass 28 | dectest: ddCompare 29 | dectest: ddCompareSig 30 | dectest: ddCompareTotal 31 | dectest: ddCompareTotalMag 32 | dectest: ddCopy 33 | dectest: ddCopyAbs 34 | dectest: ddCopyNegate 35 | dectest: ddCopySign 36 | dectest: ddDivide 37 | dectest: ddDivideInt 38 | dectest: ddEncode 39 | dectest: ddFMA 40 | dectest: ddInvert 41 | dectest: ddLogB 42 | dectest: ddMax 43 | dectest: ddMaxMag 44 | dectest: ddMin 45 | dectest: ddMinMag 46 | dectest: ddMinus 47 | dectest: ddMultiply 48 | dectest: ddNextMinus 49 | dectest: ddNextPlus 50 | dectest: ddNextToward 51 | dectest: ddOr 52 | dectest: ddPlus 53 | dectest: ddQuantize 54 | dectest: ddReduce 55 | dectest: ddRemainder 56 | dectest: ddRemainderNear 57 | dectest: ddRotate 58 | dectest: ddSameQuantum 59 | dectest: ddScaleB 60 | dectest: ddShift 61 | dectest: ddSubtract 62 | dectest: ddToIntegral 63 | dectest: ddXor 64 | 65 | -------------------------------------------------------------------------------- /testdata/decQuad.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- decQuad.decTest -- run all decQuad decimal arithmetic tests -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | -- decQuad tests 22 | dectest: dqAbs 23 | dectest: dqAdd 24 | dectest: dqAnd 25 | dectest: dqBase 26 | dectest: dqCanonical 27 | dectest: dqClass 28 | dectest: dqCompare 29 | dectest: dqCompareSig 30 | dectest: dqCompareTotal 31 | dectest: dqCompareTotalMag 32 | dectest: dqCopy 33 | dectest: dqCopyAbs 34 | dectest: dqCopyNegate 35 | dectest: dqCopySign 36 | dectest: dqDivide 37 | dectest: dqDivideInt 38 | dectest: dqEncode 39 | dectest: dqFMA 40 | dectest: dqInvert 41 | dectest: dqLogB 42 | dectest: dqMax 43 | dectest: dqMaxMag 44 | dectest: dqMin 45 | dectest: dqMinMag 46 | dectest: dqMinus 47 | dectest: dqMultiply 48 | dectest: dqNextMinus 49 | dectest: dqNextPlus 50 | dectest: dqNextToward 51 | dectest: dqOr 52 | dectest: dqPlus 53 | dectest: dqQuantize 54 | dectest: dqReduce 55 | dectest: dqRemainder 56 | dectest: dqRemainderNear 57 | dectest: dqRotate 58 | dectest: dqSameQuantum 59 | dectest: dqScaleB 60 | dectest: dqShift 61 | dectest: dqSubtract 62 | dectest: dqToIntegral 63 | dectest: dqXor 64 | 65 | -------------------------------------------------------------------------------- /testdata/testall.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- testall.decTest -- run all general decimal arithmetic testcases -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | -- core tests (using Extended: 1) -------------------------------------- 22 | dectest: base 23 | 24 | dectest: abs 25 | dectest: add 26 | dectest: and 27 | dectest: clamp 28 | dectest: class 29 | dectest: compare 30 | dectest: comparesig 31 | dectest: comparetotal 32 | dectest: comparetotmag 33 | dectest: copy 34 | dectest: copyabs 35 | dectest: copynegate 36 | dectest: copysign 37 | dectest: divide 38 | dectest: divideint 39 | dectest: exp 40 | dectest: fma 41 | dectest: inexact 42 | dectest: invert 43 | dectest: ln 44 | dectest: logb 45 | dectest: log10 46 | dectest: max 47 | dectest: maxmag 48 | dectest: min 49 | dectest: minmag 50 | dectest: minus 51 | dectest: multiply 52 | dectest: nextminus 53 | dectest: nextplus 54 | dectest: nexttoward 55 | dectest: or 56 | dectest: plus 57 | dectest: power 58 | dectest: powersqrt 59 | dectest: quantize 60 | dectest: randoms 61 | dectest: reduce -- [was called normalize] 62 | dectest: remainder 63 | dectest: remaindernear 64 | dectest: rescale -- [obsolete] 65 | dectest: rotate 66 | dectest: rounding 67 | dectest: samequantum 68 | dectest: scaleb 69 | dectest: shift 70 | dectest: squareroot 71 | dectest: subtract 72 | dectest: tointegral 73 | dectest: tointegralx 74 | dectest: trim 75 | dectest: xor 76 | 77 | -- General 31->33-digit boundary tests 78 | dectest: randombound32 79 | 80 | -------------------------------------------------------------------------------- /decnumber-sys/decnumber/decPacked.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------ */ 2 | /* Packed Decimal conversion module header */ 3 | /* ------------------------------------------------------------------ */ 4 | /* Copyright (c) IBM Corporation, 2000, 2005. All rights reserved. */ 5 | /* */ 6 | /* This software is made available under the terms of the */ 7 | /* ICU License -- ICU 1.8.1 and later. */ 8 | /* */ 9 | /* The description and User's Guide ("The decNumber C Library") for */ 10 | /* this software is called decNumber.pdf. This document is */ 11 | /* available, together with arithmetic and format specifications, */ 12 | /* testcases, and Web links, on the General Decimal Arithmetic page. */ 13 | /* */ 14 | /* Please send comments, suggestions, and corrections to the author: */ 15 | /* mfc@uk.ibm.com */ 16 | /* Mike Cowlishaw, IBM Fellow */ 17 | /* IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK */ 18 | /* ------------------------------------------------------------------ */ 19 | 20 | #if !defined(DECPACKED) 21 | #define DECPACKED 22 | #define DECPNAME "decPacked" /* Short name */ 23 | #define DECPFULLNAME "Packed Decimal conversions" /* Verbose name */ 24 | #define DECPAUTHOR "Mike Cowlishaw" /* Who to blame */ 25 | 26 | #define DECPACKED_DefP 32 /* default precision */ 27 | 28 | #ifndef DECNUMDIGITS 29 | #define DECNUMDIGITS DECPACKED_DefP /* size if not already defined*/ 30 | #endif 31 | #include "decNumber.h" /* context and number library */ 32 | 33 | /* Sign nibble constants */ 34 | #if !defined(DECPPLUSALT) 35 | #define DECPPLUSALT 0x0A /* alternate plus nibble */ 36 | #define DECPMINUSALT 0x0B /* alternate minus nibble */ 37 | #define DECPPLUS 0x0C /* preferred plus nibble */ 38 | #define DECPMINUS 0x0D /* preferred minus nibble */ 39 | #define DECPPLUSALT2 0x0E /* alternate plus nibble */ 40 | #define DECPUNSIGNED 0x0F /* alternate plus nibble (unsigned) */ 41 | #endif 42 | 43 | /* ---------------------------------------------------------------- */ 44 | /* decPacked public routines */ 45 | /* ---------------------------------------------------------------- */ 46 | /* Conversions */ 47 | uint8_t * decPackedFromNumber(uint8_t *, int32_t, int32_t *, 48 | const decNumber *); 49 | decNumber * decPackedToNumber(const uint8_t *, int32_t, const int32_t *, 50 | decNumber *); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /decnumber-sys/decnumber/readme.txt: -------------------------------------------------------------------------------- 1 | This is the readme.txt for the decNumber package. It includes 2 | instructions for compiling and testing the package; please read them. 3 | --------------------------------------------------------------------- 4 | 5 | decNumber is distributed in two forms; as a complete package from 6 | the International Components for Unicode (ICU) site (under an as-is 7 | license), or as a collection of Open Source files from the GCC source 8 | repository (under the GPL license). 9 | 10 | If you are using the GCC files, you can obtain the documentation, the 11 | example files mentioned below, and this readme from the General 12 | Decimal Arithmetic web page -- http://speleotrove.com/decimal/ (the 13 | URL for the open source files is also linked from there). 14 | 15 | 16 | The ICU package 17 | --------------- 18 | 19 | The ICU package includes the files: 20 | 21 | * readme.txt (this file) 22 | 23 | * ICU-license.html 24 | 25 | * decNumber.pdf (documentation) 26 | 27 | * The .c and .h file for each module in the package (see the 28 | decNumber documentation), together with other included files. 29 | 30 | * The .c files for each of the examples (example1.c through 31 | example8.c). 32 | 33 | The ICU package is made available under the terms of the ICU License 34 | (ICU 1.8.1 and later) included in the package as ICU-license.html. 35 | Your use of that package indicates your acceptance of the terms and 36 | conditions of that Agreement. 37 | 38 | 39 | To use and check decNumber 40 | -------------------------- 41 | 42 | Please read the appropriate license and documentation before using 43 | this package. If you are upgrading an existing use of decNumber 44 | (with version <= 3.37) please read the Changes Appendix for later 45 | versions -- you may need to change the DECLITEND flag. 46 | 47 | 1. Compile and link example1.c, decNumber.c, and decContext.c 48 | For instance, use: 49 | 50 | gcc -o example1 example1.c decNumber.c decContext.c 51 | 52 | Note: If your compiler does not provide stdint.h or if your C 53 | compiler does not handle line comments (// ...), then see the 54 | User's Guide section in the documentation for further information 55 | (including a sample minimal stdint.h). 56 | 57 | The use of compiler optimization is strongly recommended (e.g., 58 | -O3 for GCC or /O2 for Visual Studio). 59 | 60 | 2. Run example1 with two numeric arguments, for example: 61 | 62 | example1 1.23 1.27 63 | 64 | this should display: 65 | 66 | 1.23 + 1.27 => 2.50 67 | 68 | 3. Similarly, try the other examples, at will. 69 | 70 | Examples 2->4 require three files to be compiled, like Example 1. 71 | 72 | Example 5 requires decimal64.c in addition to the core modules. 73 | 74 | Example 6 requires decPacked.c in addition to the core modules. 75 | 76 | Example 7 requires only example7.c decContext.c and decQuad.c 77 | 78 | Example 8 requires example8.c, decContext.c, and decQuad.c, plus 79 | decNumber.c, decimal128.c, and decimal64.c (the latter 80 | for shared tables and code) 81 | 82 | -------------------------------------------------------------------------------- /testdata/copy.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- copy.decTest -- quiet copy -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | extended: 1 22 | precision: 9 23 | rounding: half_up 24 | maxExponent: 999 25 | minExponent: -999 26 | 27 | -- Sanity check 28 | cpyx001 copy +7.50 -> 7.50 29 | 30 | -- Infinities 31 | cpyx011 copy Infinity -> Infinity 32 | cpyx012 copy -Infinity -> -Infinity 33 | 34 | -- NaNs, 0 payload 35 | cpyx021 copy NaN -> NaN 36 | cpyx022 copy -NaN -> -NaN 37 | cpyx023 copy sNaN -> sNaN 38 | cpyx024 copy -sNaN -> -sNaN 39 | 40 | -- NaNs, non-0 payload 41 | cpyx031 copy NaN10 -> NaN10 42 | cpyx032 copy -NaN10 -> -NaN10 43 | cpyx033 copy sNaN10 -> sNaN10 44 | cpyx034 copy -sNaN10 -> -sNaN10 45 | cpyx035 copy NaN7 -> NaN7 46 | cpyx036 copy -NaN7 -> -NaN7 47 | cpyx037 copy sNaN101 -> sNaN101 48 | cpyx038 copy -sNaN101 -> -sNaN101 49 | 50 | -- finites 51 | cpyx101 copy 7 -> 7 52 | cpyx102 copy -7 -> -7 53 | cpyx103 copy 75 -> 75 54 | cpyx104 copy -75 -> -75 55 | cpyx105 copy 7.50 -> 7.50 56 | cpyx106 copy -7.50 -> -7.50 57 | cpyx107 copy 7.500 -> 7.500 58 | cpyx108 copy -7.500 -> -7.500 59 | 60 | -- zeros 61 | cpyx111 copy 0 -> 0 62 | cpyx112 copy -0 -> -0 63 | cpyx113 copy 0E+4 -> 0E+4 64 | cpyx114 copy -0E+4 -> -0E+4 65 | cpyx115 copy 0.0000 -> 0.0000 66 | cpyx116 copy -0.0000 -> -0.0000 67 | cpyx117 copy 0E-141 -> 0E-141 68 | cpyx118 copy -0E-141 -> -0E-141 69 | 70 | -- full coefficients, alternating bits 71 | cpyx121 copy 268268268 -> 268268268 72 | cpyx122 copy -268268268 -> -268268268 73 | cpyx123 copy 134134134 -> 134134134 74 | cpyx124 copy -134134134 -> -134134134 75 | 76 | -- Nmax, Nmin, Ntiny 77 | cpyx131 copy 9.99999999E+999 -> 9.99999999E+999 78 | cpyx132 copy 1E-999 -> 1E-999 79 | cpyx133 copy 1.00000000E-999 -> 1.00000000E-999 80 | cpyx134 copy 1E-1007 -> 1E-1007 81 | 82 | cpyx135 copy -1E-1007 -> -1E-1007 83 | cpyx136 copy -1.00000000E-999 -> -1.00000000E-999 84 | cpyx137 copy -1E-999 -> -1E-999 85 | cpyx138 copy -9.99999999E+999 -> -9.99999999E+999 86 | -------------------------------------------------------------------------------- /testdata/copyabs.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- copyabs.decTest -- quiet copy and set sign to zero -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | extended: 1 22 | precision: 9 23 | rounding: half_up 24 | maxExponent: 999 25 | minExponent: -999 26 | 27 | -- Sanity check 28 | cpax001 copyabs +7.50 -> 7.50 29 | 30 | -- Infinities 31 | cpax011 copyabs Infinity -> Infinity 32 | cpax012 copyabs -Infinity -> Infinity 33 | 34 | -- NaNs, 0 payload 35 | cpax021 copyabs NaN -> NaN 36 | cpax022 copyabs -NaN -> NaN 37 | cpax023 copyabs sNaN -> sNaN 38 | cpax024 copyabs -sNaN -> sNaN 39 | 40 | -- NaNs, non-0 payload 41 | cpax031 copyabs NaN10 -> NaN10 42 | cpax032 copyabs -NaN15 -> NaN15 43 | cpax033 copyabs sNaN15 -> sNaN15 44 | cpax034 copyabs -sNaN10 -> sNaN10 45 | cpax035 copyabs NaN7 -> NaN7 46 | cpax036 copyabs -NaN7 -> NaN7 47 | cpax037 copyabs sNaN101 -> sNaN101 48 | cpax038 copyabs -sNaN101 -> sNaN101 49 | 50 | -- finites 51 | cpax101 copyabs 7 -> 7 52 | cpax102 copyabs -7 -> 7 53 | cpax103 copyabs 75 -> 75 54 | cpax104 copyabs -75 -> 75 55 | cpax105 copyabs 7.10 -> 7.10 56 | cpax106 copyabs -7.10 -> 7.10 57 | cpax107 copyabs 7.500 -> 7.500 58 | cpax108 copyabs -7.500 -> 7.500 59 | 60 | -- zeros 61 | cpax111 copyabs 0 -> 0 62 | cpax112 copyabs -0 -> 0 63 | cpax113 copyabs 0E+6 -> 0E+6 64 | cpax114 copyabs -0E+6 -> 0E+6 65 | cpax115 copyabs 0.0000 -> 0.0000 66 | cpax116 copyabs -0.0000 -> 0.0000 67 | cpax117 copyabs 0E-141 -> 0E-141 68 | cpax118 copyabs -0E-141 -> 0E-141 69 | 70 | -- full coefficients, alternating bits 71 | cpax121 copyabs 268268268 -> 268268268 72 | cpax122 copyabs -268268268 -> 268268268 73 | cpax123 copyabs 134134134 -> 134134134 74 | cpax124 copyabs -134134134 -> 134134134 75 | 76 | -- Nmax, Nmin, Ntiny 77 | cpax131 copyabs 9.99999999E+999 -> 9.99999999E+999 78 | cpax132 copyabs 1E-999 -> 1E-999 79 | cpax133 copyabs 1.00000000E-999 -> 1.00000000E-999 80 | cpax134 copyabs 1E-1007 -> 1E-1007 81 | 82 | cpax135 copyabs -1E-1007 -> 1E-1007 83 | cpax136 copyabs -1.00000000E-999 -> 1.00000000E-999 84 | cpax137 copyabs -1E-999 -> 1E-999 85 | cpax199 copyabs -9.99999999E+999 -> 9.99999999E+999 86 | -------------------------------------------------------------------------------- /decnumber-sys/decnumber/decSingle.c: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------ */ 2 | /* decSingle.c -- decSingle operations module */ 3 | /* ------------------------------------------------------------------ */ 4 | /* Copyright (c) IBM Corporation, 2000, 2008. All rights reserved. */ 5 | /* */ 6 | /* This software is made available under the terms of the */ 7 | /* ICU License -- ICU 1.8.1 and later. */ 8 | /* */ 9 | /* The description and User's Guide ("The decNumber C Library") for */ 10 | /* this software is included in the package as decNumber.pdf. This */ 11 | /* document is also available in HTML, together with specifications, */ 12 | /* testcases, and Web links, on the General Decimal Arithmetic page. */ 13 | /* */ 14 | /* Please send comments, suggestions, and corrections to the author: */ 15 | /* mfc@uk.ibm.com */ 16 | /* Mike Cowlishaw, IBM Fellow */ 17 | /* IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK */ 18 | /* ------------------------------------------------------------------ */ 19 | /* This module comprises decSingle operations (including conversions) */ 20 | /* ------------------------------------------------------------------ */ 21 | 22 | #include "decContext.h" // public includes 23 | #include "decSingle.h" // public includes 24 | 25 | /* Constant mappings for shared code */ 26 | #define DECPMAX DECSINGLE_Pmax 27 | #define DECEMIN DECSINGLE_Emin 28 | #define DECEMAX DECSINGLE_Emax 29 | #define DECEMAXD DECSINGLE_EmaxD 30 | #define DECBYTES DECSINGLE_Bytes 31 | #define DECSTRING DECSINGLE_String 32 | #define DECECONL DECSINGLE_EconL 33 | #define DECBIAS DECSINGLE_Bias 34 | #define DECLETS DECSINGLE_Declets 35 | #define DECQTINY (-DECSINGLE_Bias) 36 | // parameters of next-wider format 37 | #define DECWBYTES DECDOUBLE_Bytes 38 | #define DECWPMAX DECDOUBLE_Pmax 39 | #define DECWECONL DECDOUBLE_EconL 40 | #define DECWBIAS DECDOUBLE_Bias 41 | 42 | /* Type and function mappings for shared code */ 43 | #define decFloat decSingle // Type name 44 | #define decFloatWider decDouble // Type name 45 | 46 | // Utility (binary results, extractors, etc.) 47 | #define decFloatFromBCD decSingleFromBCD 48 | #define decFloatFromPacked decSingleFromPacked 49 | #define decFloatFromPackedChecked decSingleFromPackedChecked 50 | #define decFloatFromString decSingleFromString 51 | #define decFloatFromWider decSingleFromWider 52 | #define decFloatGetCoefficient decSingleGetCoefficient 53 | #define decFloatGetExponent decSingleGetExponent 54 | #define decFloatSetCoefficient decSingleSetCoefficient 55 | #define decFloatSetExponent decSingleSetExponent 56 | #define decFloatShow decSingleShow 57 | #define decFloatToBCD decSingleToBCD 58 | #define decFloatToEngString decSingleToEngString 59 | #define decFloatToPacked decSingleToPacked 60 | #define decFloatToString decSingleToString 61 | #define decFloatToWider decSingleToWider 62 | #define decFloatZero decSingleZero 63 | 64 | // Non-computational 65 | #define decFloatRadix decSingleRadix 66 | #define decFloatVersion decSingleVersion 67 | 68 | #include "decNumberLocal.h" // local includes (need DECPMAX) 69 | #include "decCommon.c" // non-basic decFloat routines 70 | // [Do not include decBasic.c for decimal32] 71 | 72 | -------------------------------------------------------------------------------- /testdata/ddCopy.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- ddCopy.decTest -- quiet decDouble copy -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | -- All operands and results are decDoubles. 22 | precision: 16 23 | maxExponent: 384 24 | minExponent: -383 25 | extended: 1 26 | clamp: 1 27 | rounding: half_even 28 | 29 | -- Sanity check 30 | ddcpy001 copy +7.50 -> 7.50 31 | 32 | -- Infinities 33 | ddcpy011 copy Infinity -> Infinity 34 | ddcpy012 copy -Infinity -> -Infinity 35 | 36 | -- NaNs, 0 payload 37 | ddcpy021 copy NaN -> NaN 38 | ddcpy022 copy -NaN -> -NaN 39 | ddcpy023 copy sNaN -> sNaN 40 | ddcpy024 copy -sNaN -> -sNaN 41 | 42 | -- NaNs, non-0 payload 43 | ddcpy031 copy NaN10 -> NaN10 44 | ddcpy032 copy -NaN10 -> -NaN10 45 | ddcpy033 copy sNaN10 -> sNaN10 46 | ddcpy034 copy -sNaN10 -> -sNaN10 47 | ddcpy035 copy NaN7 -> NaN7 48 | ddcpy036 copy -NaN7 -> -NaN7 49 | ddcpy037 copy sNaN101 -> sNaN101 50 | ddcpy038 copy -sNaN101 -> -sNaN101 51 | 52 | -- finites 53 | ddcpy101 copy 7 -> 7 54 | ddcpy102 copy -7 -> -7 55 | ddcpy103 copy 75 -> 75 56 | ddcpy104 copy -75 -> -75 57 | ddcpy105 copy 7.50 -> 7.50 58 | ddcpy106 copy -7.50 -> -7.50 59 | ddcpy107 copy 7.500 -> 7.500 60 | ddcpy108 copy -7.500 -> -7.500 61 | 62 | -- zeros 63 | ddcpy111 copy 0 -> 0 64 | ddcpy112 copy -0 -> -0 65 | ddcpy113 copy 0E+4 -> 0E+4 66 | ddcpy114 copy -0E+4 -> -0E+4 67 | ddcpy115 copy 0.0000 -> 0.0000 68 | ddcpy116 copy -0.0000 -> -0.0000 69 | ddcpy117 copy 0E-141 -> 0E-141 70 | ddcpy118 copy -0E-141 -> -0E-141 71 | 72 | -- full coefficients, alternating bits 73 | ddcpy121 copy 2682682682682682 -> 2682682682682682 74 | ddcpy122 copy -2682682682682682 -> -2682682682682682 75 | ddcpy123 copy 1341341341341341 -> 1341341341341341 76 | ddcpy124 copy -1341341341341341 -> -1341341341341341 77 | 78 | -- Nmax, Nmin, Ntiny 79 | ddcpy131 copy 9.999999999999999E+384 -> 9.999999999999999E+384 80 | ddcpy132 copy 1E-383 -> 1E-383 81 | ddcpy133 copy 1.000000000000000E-383 -> 1.000000000000000E-383 82 | ddcpy134 copy 1E-398 -> 1E-398 83 | 84 | ddcpy135 copy -1E-398 -> -1E-398 85 | ddcpy136 copy -1.000000000000000E-383 -> -1.000000000000000E-383 86 | ddcpy137 copy -1E-383 -> -1E-383 87 | ddcpy138 copy -9.999999999999999E+384 -> -9.999999999999999E+384 88 | -------------------------------------------------------------------------------- /testdata/copynegate.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- copynegate.decTest -- quiet copy and negate -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | extended: 1 22 | precision: 9 23 | rounding: half_up 24 | maxExponent: 999 25 | minExponent: -999 26 | 27 | -- Sanity check 28 | cpnx001 copynegate +7.50 -> -7.50 29 | 30 | -- Infinities 31 | cpnx011 copynegate Infinity -> -Infinity 32 | cpnx012 copynegate -Infinity -> Infinity 33 | 34 | -- NaNs, 0 payload 35 | cpnx021 copynegate NaN -> -NaN 36 | cpnx022 copynegate -NaN -> NaN 37 | cpnx023 copynegate sNaN -> -sNaN 38 | cpnx024 copynegate -sNaN -> sNaN 39 | 40 | -- NaNs, non-0 payload 41 | cpnx031 copynegate NaN13 -> -NaN13 42 | cpnx032 copynegate -NaN13 -> NaN13 43 | cpnx033 copynegate sNaN13 -> -sNaN13 44 | cpnx034 copynegate -sNaN13 -> sNaN13 45 | cpnx035 copynegate NaN70 -> -NaN70 46 | cpnx036 copynegate -NaN70 -> NaN70 47 | cpnx037 copynegate sNaN101 -> -sNaN101 48 | cpnx038 copynegate -sNaN101 -> sNaN101 49 | 50 | -- finites 51 | cpnx101 copynegate 7 -> -7 52 | cpnx102 copynegate -7 -> 7 53 | cpnx103 copynegate 75 -> -75 54 | cpnx104 copynegate -75 -> 75 55 | cpnx105 copynegate 7.50 -> -7.50 56 | cpnx106 copynegate -7.50 -> 7.50 57 | cpnx107 copynegate 7.500 -> -7.500 58 | cpnx108 copynegate -7.500 -> 7.500 59 | 60 | -- zeros 61 | cpnx111 copynegate 0 -> -0 62 | cpnx112 copynegate -0 -> 0 63 | cpnx113 copynegate 0E+4 -> -0E+4 64 | cpnx114 copynegate -0E+4 -> 0E+4 65 | cpnx115 copynegate 0.0000 -> -0.0000 66 | cpnx116 copynegate -0.0000 -> 0.0000 67 | cpnx117 copynegate 0E-141 -> -0E-141 68 | cpnx118 copynegate -0E-141 -> 0E-141 69 | 70 | -- full coefficients, alternating bits 71 | cpnx121 copynegate 268268268 -> -268268268 72 | cpnx122 copynegate -268268268 -> 268268268 73 | cpnx123 copynegate 134134134 -> -134134134 74 | cpnx124 copynegate -134134134 -> 134134134 75 | 76 | -- Nmax, Nmin, Ntiny 77 | cpnx131 copynegate 9.99999999E+999 -> -9.99999999E+999 78 | cpnx132 copynegate 1E-999 -> -1E-999 79 | cpnx133 copynegate 1.00000000E-999 -> -1.00000000E-999 80 | cpnx134 copynegate 1E-1007 -> -1E-1007 81 | 82 | cpnx135 copynegate -1E-1007 -> 1E-1007 83 | cpnx136 copynegate -1.00000000E-999 -> 1.00000000E-999 84 | cpnx137 copynegate -1E-999 -> 1E-999 85 | cpnx138 copynegate -9.99999999E+999 -> 9.99999999E+999 86 | -------------------------------------------------------------------------------- /testdata/ddCopyAbs.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- ddCopyAbs.decTest -- quiet decDouble copy and set sign to zero -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | -- All operands and results are decDoubles. 22 | precision: 16 23 | maxExponent: 384 24 | minExponent: -383 25 | extended: 1 26 | clamp: 1 27 | rounding: half_even 28 | 29 | -- Sanity check 30 | ddcpa001 copyabs +7.50 -> 7.50 31 | 32 | -- Infinities 33 | ddcpa011 copyabs Infinity -> Infinity 34 | ddcpa012 copyabs -Infinity -> Infinity 35 | 36 | -- NaNs, 0 payload 37 | ddcpa021 copyabs NaN -> NaN 38 | ddcpa022 copyabs -NaN -> NaN 39 | ddcpa023 copyabs sNaN -> sNaN 40 | ddcpa024 copyabs -sNaN -> sNaN 41 | 42 | -- NaNs, non-0 payload 43 | ddcpa031 copyabs NaN10 -> NaN10 44 | ddcpa032 copyabs -NaN15 -> NaN15 45 | ddcpa033 copyabs sNaN15 -> sNaN15 46 | ddcpa034 copyabs -sNaN10 -> sNaN10 47 | ddcpa035 copyabs NaN7 -> NaN7 48 | ddcpa036 copyabs -NaN7 -> NaN7 49 | ddcpa037 copyabs sNaN101 -> sNaN101 50 | ddcpa038 copyabs -sNaN101 -> sNaN101 51 | 52 | -- finites 53 | ddcpa101 copyabs 7 -> 7 54 | ddcpa102 copyabs -7 -> 7 55 | ddcpa103 copyabs 75 -> 75 56 | ddcpa104 copyabs -75 -> 75 57 | ddcpa105 copyabs 7.10 -> 7.10 58 | ddcpa106 copyabs -7.10 -> 7.10 59 | ddcpa107 copyabs 7.500 -> 7.500 60 | ddcpa108 copyabs -7.500 -> 7.500 61 | 62 | -- zeros 63 | ddcpa111 copyabs 0 -> 0 64 | ddcpa112 copyabs -0 -> 0 65 | ddcpa113 copyabs 0E+6 -> 0E+6 66 | ddcpa114 copyabs -0E+6 -> 0E+6 67 | ddcpa115 copyabs 0.0000 -> 0.0000 68 | ddcpa116 copyabs -0.0000 -> 0.0000 69 | ddcpa117 copyabs 0E-141 -> 0E-141 70 | ddcpa118 copyabs -0E-141 -> 0E-141 71 | 72 | -- full coefficients, alternating bits 73 | ddcpa121 copyabs 2682682682682682 -> 2682682682682682 74 | ddcpa122 copyabs -2682682682682682 -> 2682682682682682 75 | ddcpa123 copyabs 1341341341341341 -> 1341341341341341 76 | ddcpa124 copyabs -1341341341341341 -> 1341341341341341 77 | 78 | -- Nmax, Nmin, Ntiny 79 | ddcpa131 copyabs 9.999999999999999E+384 -> 9.999999999999999E+384 80 | ddcpa132 copyabs 1E-383 -> 1E-383 81 | ddcpa133 copyabs 1.000000000000000E-383 -> 1.000000000000000E-383 82 | ddcpa134 copyabs 1E-398 -> 1E-398 83 | 84 | ddcpa135 copyabs -1E-398 -> 1E-398 85 | ddcpa136 copyabs -1.000000000000000E-383 -> 1.000000000000000E-383 86 | ddcpa137 copyabs -1E-383 -> 1E-383 87 | ddcpa138 copyabs -9.999999999999999E+384 -> 9.999999999999999E+384 88 | -------------------------------------------------------------------------------- /testdata/ddPlus.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- ddPlus.decTest -- decDouble 0+x -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | -- All operands and results are decDoubles. 22 | precision: 16 23 | maxExponent: 384 24 | minExponent: -383 25 | extended: 1 26 | clamp: 1 27 | rounding: half_even 28 | 29 | -- Sanity check 30 | ddpls001 plus +7.50 -> 7.50 31 | 32 | -- Infinities 33 | ddpls011 plus Infinity -> Infinity 34 | ddpls012 plus -Infinity -> -Infinity 35 | 36 | -- NaNs, 0 payload 37 | ddpls021 plus NaN -> NaN 38 | ddpls022 plus -NaN -> -NaN 39 | ddpls023 plus sNaN -> NaN Invalid_operation 40 | ddpls024 plus -sNaN -> -NaN Invalid_operation 41 | 42 | -- NaNs, non-0 payload 43 | ddpls031 plus NaN13 -> NaN13 44 | ddpls032 plus -NaN13 -> -NaN13 45 | ddpls033 plus sNaN13 -> NaN13 Invalid_operation 46 | ddpls034 plus -sNaN13 -> -NaN13 Invalid_operation 47 | ddpls035 plus NaN70 -> NaN70 48 | ddpls036 plus -NaN70 -> -NaN70 49 | ddpls037 plus sNaN101 -> NaN101 Invalid_operation 50 | ddpls038 plus -sNaN101 -> -NaN101 Invalid_operation 51 | 52 | -- finites 53 | ddpls101 plus 7 -> 7 54 | ddpls102 plus -7 -> -7 55 | ddpls103 plus 75 -> 75 56 | ddpls104 plus -75 -> -75 57 | ddpls105 plus 7.50 -> 7.50 58 | ddpls106 plus -7.50 -> -7.50 59 | ddpls107 plus 7.500 -> 7.500 60 | ddpls108 plus -7.500 -> -7.500 61 | 62 | -- zeros 63 | ddpls111 plus 0 -> 0 64 | ddpls112 plus -0 -> 0 65 | ddpls113 plus 0E+4 -> 0E+4 66 | ddpls114 plus -0E+4 -> 0E+4 67 | ddpls115 plus 0.0000 -> 0.0000 68 | ddpls116 plus -0.0000 -> 0.0000 69 | ddpls117 plus 0E-141 -> 0E-141 70 | ddpls118 plus -0E-141 -> 0E-141 71 | 72 | -- full coefficients, alternating bits 73 | ddpls121 plus 2682682682682682 -> 2682682682682682 74 | ddpls122 plus -2682682682682682 -> -2682682682682682 75 | ddpls123 plus 1341341341341341 -> 1341341341341341 76 | ddpls124 plus -1341341341341341 -> -1341341341341341 77 | 78 | -- Nmax, Nmin, Ntiny 79 | ddpls131 plus 9.999999999999999E+384 -> 9.999999999999999E+384 80 | ddpls132 plus 1E-383 -> 1E-383 81 | ddpls133 plus 1.000000000000000E-383 -> 1.000000000000000E-383 82 | ddpls134 plus 1E-398 -> 1E-398 Subnormal 83 | 84 | ddpls135 plus -1E-398 -> -1E-398 Subnormal 85 | ddpls136 plus -1.000000000000000E-383 -> -1.000000000000000E-383 86 | ddpls137 plus -1E-383 -> -1E-383 87 | ddpls138 plus -9.999999999999999E+384 -> -9.999999999999999E+384 88 | -------------------------------------------------------------------------------- /testdata/ddMinus.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- ddMinus.decTest -- decDouble 0-x -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | -- All operands and results are decDoubles. 22 | precision: 16 23 | maxExponent: 384 24 | minExponent: -383 25 | extended: 1 26 | clamp: 1 27 | rounding: half_even 28 | 29 | -- Sanity check 30 | ddmns001 minus +7.50 -> -7.50 31 | 32 | -- Infinities 33 | ddmns011 minus Infinity -> -Infinity 34 | ddmns012 minus -Infinity -> Infinity 35 | 36 | -- NaNs, 0 payload 37 | ddmns021 minus NaN -> NaN 38 | ddmns022 minus -NaN -> -NaN 39 | ddmns023 minus sNaN -> NaN Invalid_operation 40 | ddmns024 minus -sNaN -> -NaN Invalid_operation 41 | 42 | -- NaNs, non-0 payload 43 | ddmns031 minus NaN13 -> NaN13 44 | ddmns032 minus -NaN13 -> -NaN13 45 | ddmns033 minus sNaN13 -> NaN13 Invalid_operation 46 | ddmns034 minus -sNaN13 -> -NaN13 Invalid_operation 47 | ddmns035 minus NaN70 -> NaN70 48 | ddmns036 minus -NaN70 -> -NaN70 49 | ddmns037 minus sNaN101 -> NaN101 Invalid_operation 50 | ddmns038 minus -sNaN101 -> -NaN101 Invalid_operation 51 | 52 | -- finites 53 | ddmns101 minus 7 -> -7 54 | ddmns102 minus -7 -> 7 55 | ddmns103 minus 75 -> -75 56 | ddmns104 minus -75 -> 75 57 | ddmns105 minus 7.50 -> -7.50 58 | ddmns106 minus -7.50 -> 7.50 59 | ddmns107 minus 7.500 -> -7.500 60 | ddmns108 minus -7.500 -> 7.500 61 | 62 | -- zeros 63 | ddmns111 minus 0 -> 0 64 | ddmns112 minus -0 -> 0 65 | ddmns113 minus 0E+4 -> 0E+4 66 | ddmns114 minus -0E+4 -> 0E+4 67 | ddmns115 minus 0.0000 -> 0.0000 68 | ddmns116 minus -0.0000 -> 0.0000 69 | ddmns117 minus 0E-141 -> 0E-141 70 | ddmns118 minus -0E-141 -> 0E-141 71 | 72 | -- full coefficients, alternating bits 73 | ddmns121 minus 2682682682682682 -> -2682682682682682 74 | ddmns122 minus -2682682682682682 -> 2682682682682682 75 | ddmns123 minus 1341341341341341 -> -1341341341341341 76 | ddmns124 minus -1341341341341341 -> 1341341341341341 77 | 78 | -- Nmax, Nmin, Ntiny 79 | ddmns131 minus 9.999999999999999E+384 -> -9.999999999999999E+384 80 | ddmns132 minus 1E-383 -> -1E-383 81 | ddmns133 minus 1.000000000000000E-383 -> -1.000000000000000E-383 82 | ddmns134 minus 1E-398 -> -1E-398 Subnormal 83 | 84 | ddmns135 minus -1E-398 -> 1E-398 Subnormal 85 | ddmns136 minus -1.000000000000000E-383 -> 1.000000000000000E-383 86 | ddmns137 minus -1E-383 -> 1E-383 87 | ddmns138 minus -9.999999999999999E+384 -> 9.999999999999999E+384 88 | -------------------------------------------------------------------------------- /testdata/ddClass.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- ddClass.decTest -- decDouble Class operations -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | -- [New 2006.11.27] 22 | precision: 16 23 | maxExponent: 384 24 | minExponent: -383 25 | extended: 1 26 | clamp: 1 27 | rounding: half_even 28 | 29 | ddcla001 class 0 -> +Zero 30 | ddcla002 class 0.00 -> +Zero 31 | ddcla003 class 0E+5 -> +Zero 32 | ddcla004 class 1E-396 -> +Subnormal 33 | ddcla005 class 0.1E-383 -> +Subnormal 34 | ddcla006 class 0.999999999999999E-383 -> +Subnormal 35 | ddcla007 class 1.000000000000000E-383 -> +Normal 36 | ddcla008 class 1E-383 -> +Normal 37 | ddcla009 class 1E-100 -> +Normal 38 | ddcla010 class 1E-10 -> +Normal 39 | ddcla012 class 1E-1 -> +Normal 40 | ddcla013 class 1 -> +Normal 41 | ddcla014 class 2.50 -> +Normal 42 | ddcla015 class 100.100 -> +Normal 43 | ddcla016 class 1E+30 -> +Normal 44 | ddcla017 class 1E+384 -> +Normal 45 | ddcla018 class 9.999999999999999E+384 -> +Normal 46 | ddcla019 class Inf -> +Infinity 47 | 48 | ddcla021 class -0 -> -Zero 49 | ddcla022 class -0.00 -> -Zero 50 | ddcla023 class -0E+5 -> -Zero 51 | ddcla024 class -1E-396 -> -Subnormal 52 | ddcla025 class -0.1E-383 -> -Subnormal 53 | ddcla026 class -0.999999999999999E-383 -> -Subnormal 54 | ddcla027 class -1.000000000000000E-383 -> -Normal 55 | ddcla028 class -1E-383 -> -Normal 56 | ddcla029 class -1E-100 -> -Normal 57 | ddcla030 class -1E-10 -> -Normal 58 | ddcla032 class -1E-1 -> -Normal 59 | ddcla033 class -1 -> -Normal 60 | ddcla034 class -2.50 -> -Normal 61 | ddcla035 class -100.100 -> -Normal 62 | ddcla036 class -1E+30 -> -Normal 63 | ddcla037 class -1E+384 -> -Normal 64 | ddcla038 class -9.999999999999999E+384 -> -Normal 65 | ddcla039 class -Inf -> -Infinity 66 | 67 | ddcla041 class NaN -> NaN 68 | ddcla042 class -NaN -> NaN 69 | ddcla043 class +NaN12345 -> NaN 70 | ddcla044 class sNaN -> sNaN 71 | ddcla045 class -sNaN -> sNaN 72 | ddcla046 class +sNaN12345 -> sNaN 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /testdata/ddCopyNegate.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- ddCopyNegate.decTest -- quiet decDouble copy and negate -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | -- All operands and results are decDoubles. 22 | precision: 16 23 | maxExponent: 384 24 | minExponent: -383 25 | extended: 1 26 | clamp: 1 27 | rounding: half_even 28 | 29 | -- Sanity check 30 | ddcpn001 copynegate +7.50 -> -7.50 31 | 32 | -- Infinities 33 | ddcpn011 copynegate Infinity -> -Infinity 34 | ddcpn012 copynegate -Infinity -> Infinity 35 | 36 | -- NaNs, 0 payload 37 | ddcpn021 copynegate NaN -> -NaN 38 | ddcpn022 copynegate -NaN -> NaN 39 | ddcpn023 copynegate sNaN -> -sNaN 40 | ddcpn024 copynegate -sNaN -> sNaN 41 | 42 | -- NaNs, non-0 payload 43 | ddcpn031 copynegate NaN13 -> -NaN13 44 | ddcpn032 copynegate -NaN13 -> NaN13 45 | ddcpn033 copynegate sNaN13 -> -sNaN13 46 | ddcpn034 copynegate -sNaN13 -> sNaN13 47 | ddcpn035 copynegate NaN70 -> -NaN70 48 | ddcpn036 copynegate -NaN70 -> NaN70 49 | ddcpn037 copynegate sNaN101 -> -sNaN101 50 | ddcpn038 copynegate -sNaN101 -> sNaN101 51 | 52 | -- finites 53 | ddcpn101 copynegate 7 -> -7 54 | ddcpn102 copynegate -7 -> 7 55 | ddcpn103 copynegate 75 -> -75 56 | ddcpn104 copynegate -75 -> 75 57 | ddcpn105 copynegate 7.50 -> -7.50 58 | ddcpn106 copynegate -7.50 -> 7.50 59 | ddcpn107 copynegate 7.500 -> -7.500 60 | ddcpn108 copynegate -7.500 -> 7.500 61 | 62 | -- zeros 63 | ddcpn111 copynegate 0 -> -0 64 | ddcpn112 copynegate -0 -> 0 65 | ddcpn113 copynegate 0E+4 -> -0E+4 66 | ddcpn114 copynegate -0E+4 -> 0E+4 67 | ddcpn115 copynegate 0.0000 -> -0.0000 68 | ddcpn116 copynegate -0.0000 -> 0.0000 69 | ddcpn117 copynegate 0E-141 -> -0E-141 70 | ddcpn118 copynegate -0E-141 -> 0E-141 71 | 72 | -- full coefficients, alternating bits 73 | ddcpn121 copynegate 2682682682682682 -> -2682682682682682 74 | ddcpn122 copynegate -2682682682682682 -> 2682682682682682 75 | ddcpn123 copynegate 1341341341341341 -> -1341341341341341 76 | ddcpn124 copynegate -1341341341341341 -> 1341341341341341 77 | 78 | -- Nmax, Nmin, Ntiny 79 | ddcpn131 copynegate 9.999999999999999E+384 -> -9.999999999999999E+384 80 | ddcpn132 copynegate 1E-383 -> -1E-383 81 | ddcpn133 copynegate 1.000000000000000E-383 -> -1.000000000000000E-383 82 | ddcpn134 copynegate 1E-398 -> -1E-398 83 | 84 | ddcpn135 copynegate -1E-398 -> 1E-398 85 | ddcpn136 copynegate -1.000000000000000E-383 -> 1.000000000000000E-383 86 | ddcpn137 copynegate -1E-383 -> 1E-383 87 | ddcpn138 copynegate -9.999999999999999E+384 -> 9.999999999999999E+384 88 | -------------------------------------------------------------------------------- /dec/src/error.rs: -------------------------------------------------------------------------------- 1 | // Copyright Materialize, Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License in the LICENSE file at the 6 | // root of this repository, or online at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | use std::error::Error; 17 | use std::fmt; 18 | 19 | /// An error indicating that a string is not a valid decimal number. 20 | #[derive(Debug, Eq, PartialEq)] 21 | pub struct ParseDecimalError; 22 | 23 | impl fmt::Display for ParseDecimalError { 24 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 25 | f.write_str("invalid decimal syntax") 26 | } 27 | } 28 | 29 | impl Error for ParseDecimalError {} 30 | 31 | /// An error indicating that a precision is not valid for a given context. 32 | #[derive(Debug, Eq, PartialEq)] 33 | pub struct InvalidPrecisionError; 34 | 35 | impl fmt::Display for InvalidPrecisionError { 36 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 37 | f.write_str("invalid decimal precision") 38 | } 39 | } 40 | 41 | impl Error for InvalidPrecisionError {} 42 | 43 | /// An error indicating that a minimum exponent or maximum exponent is not valid 44 | /// for a given context. 45 | #[derive(Debug, Eq, PartialEq)] 46 | pub struct InvalidExponentError; 47 | 48 | impl fmt::Display for InvalidExponentError { 49 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 50 | f.write_str("invalid decimal exponent") 51 | } 52 | } 53 | 54 | impl Error for InvalidExponentError {} 55 | 56 | /// An error indicating that a value cannot be cast to a primitive type. 57 | /// 58 | /// Causes for this failure include calling cast functions on values: 59 | /// - Representing infinity or NaN 60 | /// - With non-zero exponent values 61 | /// - Whose coefficient doesn't fit into the target, e.g. values that require 62 | /// too many digits of precision. 63 | #[derive(Debug, Eq, PartialEq)] 64 | pub struct TryFromDecimalError; 65 | 66 | impl fmt::Display for TryFromDecimalError { 67 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 68 | f.write_str("decimal cannot be expressed in target primitive type") 69 | } 70 | } 71 | 72 | impl Error for TryFromDecimalError {} 73 | 74 | /// An error indicating a value cannot be precisely cast to a Decimal value, e.g. 75 | /// the cast requires truncating significant digits. 76 | #[derive(Debug, Eq, PartialEq)] 77 | pub struct TryIntoDecimalError; 78 | 79 | impl fmt::Display for TryIntoDecimalError { 80 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 81 | f.write_str("value cannot be precisely expressed as decimal") 82 | } 83 | } 84 | 85 | impl Error for TryIntoDecimalError {} 86 | 87 | /// An error indicating that a value's coefficient cannot be cast to a primitive 88 | /// type. 89 | #[derive(Debug, Eq, PartialEq)] 90 | pub struct InvalidCoefficientError; 91 | 92 | impl fmt::Display for InvalidCoefficientError { 93 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 94 | f.write_str("decimal's coefficient cannot be expressed in target primitive type") 95 | } 96 | } 97 | 98 | impl Error for InvalidCoefficientError {} 99 | 100 | /// An error indicating that a value's coefficient cannot be cast to a primitive 101 | /// type. 102 | #[derive(Debug, Eq, PartialEq)] 103 | pub struct FromBcdError; 104 | 105 | impl fmt::Display for FromBcdError { 106 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 107 | f.write_str("bcd or scale value invalid, either corrupted or out of acceptable range") 108 | } 109 | } 110 | 111 | impl Error for FromBcdError {} 112 | -------------------------------------------------------------------------------- /testdata/dqClass.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- dqClass.decTest -- decQuad Class operations -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | -- [New 2006.11.27] 22 | 23 | extended: 1 24 | clamp: 1 25 | precision: 34 26 | maxExponent: 6144 27 | minExponent: -6143 28 | rounding: half_even 29 | 30 | dqcla001 class 0 -> +Zero 31 | dqcla002 class 0.00 -> +Zero 32 | dqcla003 class 0E+5 -> +Zero 33 | dqcla004 class 1E-6176 -> +Subnormal 34 | dqcla005 class 0.1E-6143 -> +Subnormal 35 | dqcla006 class 0.99999999999999999999999999999999E-6143 -> +Subnormal 36 | dqcla007 class 1.00000000000000000000000000000000E-6143 -> +Normal 37 | dqcla008 class 1E-6143 -> +Normal 38 | dqcla009 class 1E-100 -> +Normal 39 | dqcla010 class 1E-10 -> +Normal 40 | dqcla012 class 1E-1 -> +Normal 41 | dqcla013 class 1 -> +Normal 42 | dqcla014 class 2.50 -> +Normal 43 | dqcla015 class 100.100 -> +Normal 44 | dqcla016 class 1E+30 -> +Normal 45 | dqcla017 class 1E+6144 -> +Normal 46 | dqcla018 class 9.99999999999999999999999999999999E+6144 -> +Normal 47 | dqcla019 class Inf -> +Infinity 48 | 49 | dqcla021 class -0 -> -Zero 50 | dqcla022 class -0.00 -> -Zero 51 | dqcla023 class -0E+5 -> -Zero 52 | dqcla024 class -1E-6176 -> -Subnormal 53 | dqcla025 class -0.1E-6143 -> -Subnormal 54 | dqcla026 class -0.99999999999999999999999999999999E-6143 -> -Subnormal 55 | dqcla027 class -1.00000000000000000000000000000000E-6143 -> -Normal 56 | dqcla028 class -1E-6143 -> -Normal 57 | dqcla029 class -1E-100 -> -Normal 58 | dqcla030 class -1E-10 -> -Normal 59 | dqcla032 class -1E-1 -> -Normal 60 | dqcla033 class -1 -> -Normal 61 | dqcla034 class -2.50 -> -Normal 62 | dqcla035 class -100.100 -> -Normal 63 | dqcla036 class -1E+30 -> -Normal 64 | dqcla037 class -1E+6144 -> -Normal 65 | dqcla0614 class -9.99999999999999999999999999999999E+6144 -> -Normal 66 | dqcla039 class -Inf -> -Infinity 67 | 68 | dqcla041 class NaN -> NaN 69 | dqcla042 class -NaN -> NaN 70 | dqcla043 class +NaN12345 -> NaN 71 | dqcla044 class sNaN -> sNaN 72 | dqcla045 class -sNaN -> sNaN 73 | dqcla046 class +sNaN12345 -> sNaN 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /testdata/dqCopy.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- dqCopy.decTest -- quiet decQuad copy -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | -- All operands and results are decQuads. 22 | extended: 1 23 | clamp: 1 24 | precision: 34 25 | maxExponent: 6144 26 | minExponent: -6143 27 | rounding: half_even 28 | 29 | -- Sanity check 30 | dqcpy001 copy +7.50 -> 7.50 31 | 32 | -- Infinities 33 | dqcpy011 copy Infinity -> Infinity 34 | dqcpy012 copy -Infinity -> -Infinity 35 | 36 | -- NaNs, 0 payload 37 | dqcpy021 copy NaN -> NaN 38 | dqcpy022 copy -NaN -> -NaN 39 | dqcpy023 copy sNaN -> sNaN 40 | dqcpy024 copy -sNaN -> -sNaN 41 | 42 | -- NaNs, non-0 payload 43 | dqcpy031 copy NaN10 -> NaN10 44 | dqcpy032 copy -NaN10 -> -NaN10 45 | dqcpy033 copy sNaN10 -> sNaN10 46 | dqcpy034 copy -sNaN10 -> -sNaN10 47 | dqcpy035 copy NaN7 -> NaN7 48 | dqcpy036 copy -NaN7 -> -NaN7 49 | dqcpy037 copy sNaN101 -> sNaN101 50 | dqcpy038 copy -sNaN101 -> -sNaN101 51 | 52 | -- finites 53 | dqcpy101 copy 7 -> 7 54 | dqcpy102 copy -7 -> -7 55 | dqcpy103 copy 75 -> 75 56 | dqcpy104 copy -75 -> -75 57 | dqcpy105 copy 7.50 -> 7.50 58 | dqcpy106 copy -7.50 -> -7.50 59 | dqcpy107 copy 7.500 -> 7.500 60 | dqcpy108 copy -7.500 -> -7.500 61 | 62 | -- zeros 63 | dqcpy111 copy 0 -> 0 64 | dqcpy112 copy -0 -> -0 65 | dqcpy113 copy 0E+4 -> 0E+4 66 | dqcpy114 copy -0E+4 -> -0E+4 67 | dqcpy115 copy 0.0000 -> 0.0000 68 | dqcpy116 copy -0.0000 -> -0.0000 69 | dqcpy117 copy 0E-141 -> 0E-141 70 | dqcpy118 copy -0E-141 -> -0E-141 71 | 72 | -- full coefficients, alternating bits 73 | dqcpy121 copy 2682682682682682682682682682682682 -> 2682682682682682682682682682682682 74 | dqcpy122 copy -2682682682682682682682682682682682 -> -2682682682682682682682682682682682 75 | dqcpy123 copy 1341341341341341341341341341341341 -> 1341341341341341341341341341341341 76 | dqcpy124 copy -1341341341341341341341341341341341 -> -1341341341341341341341341341341341 77 | 78 | -- Nmax, Nmin, Ntiny 79 | dqcpy131 copy 9.999999999999999999999999999999999E+6144 -> 9.999999999999999999999999999999999E+6144 80 | dqcpy132 copy 1E-6143 -> 1E-6143 81 | dqcpy133 copy 1.000000000000000000000000000000000E-6143 -> 1.000000000000000000000000000000000E-6143 82 | dqcpy134 copy 1E-6176 -> 1E-6176 83 | 84 | dqcpy135 copy -1E-6176 -> -1E-6176 85 | dqcpy136 copy -1.000000000000000000000000000000000E-6143 -> -1.000000000000000000000000000000000E-6143 86 | dqcpy137 copy -1E-6143 -> -1E-6143 87 | dqcpy138 copy -9.999999999999999999999999999999999E+6144 -> -9.999999999999999999999999999999999E+6144 88 | -------------------------------------------------------------------------------- /testdata/dqCopyAbs.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- dqCopyAbs.decTest -- quiet decQuad copy and set sign to zero -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | -- All operands and results are decQuads. 22 | extended: 1 23 | clamp: 1 24 | precision: 34 25 | maxExponent: 6144 26 | minExponent: -6143 27 | rounding: half_even 28 | 29 | -- Sanity check 30 | dqcpa001 copyabs +7.50 -> 7.50 31 | 32 | -- Infinities 33 | dqcpa011 copyabs Infinity -> Infinity 34 | dqcpa012 copyabs -Infinity -> Infinity 35 | 36 | -- NaNs, 0 payload 37 | dqcpa021 copyabs NaN -> NaN 38 | dqcpa022 copyabs -NaN -> NaN 39 | dqcpa023 copyabs sNaN -> sNaN 40 | dqcpa024 copyabs -sNaN -> sNaN 41 | 42 | -- NaNs, non-0 payload 43 | dqcpa031 copyabs NaN10 -> NaN10 44 | dqcpa032 copyabs -NaN15 -> NaN15 45 | dqcpa033 copyabs sNaN15 -> sNaN15 46 | dqcpa034 copyabs -sNaN10 -> sNaN10 47 | dqcpa035 copyabs NaN7 -> NaN7 48 | dqcpa036 copyabs -NaN7 -> NaN7 49 | dqcpa037 copyabs sNaN101 -> sNaN101 50 | dqcpa038 copyabs -sNaN101 -> sNaN101 51 | 52 | -- finites 53 | dqcpa101 copyabs 7 -> 7 54 | dqcpa102 copyabs -7 -> 7 55 | dqcpa103 copyabs 75 -> 75 56 | dqcpa104 copyabs -75 -> 75 57 | dqcpa105 copyabs 7.10 -> 7.10 58 | dqcpa106 copyabs -7.10 -> 7.10 59 | dqcpa107 copyabs 7.500 -> 7.500 60 | dqcpa108 copyabs -7.500 -> 7.500 61 | 62 | -- zeros 63 | dqcpa111 copyabs 0 -> 0 64 | dqcpa112 copyabs -0 -> 0 65 | dqcpa113 copyabs 0E+6 -> 0E+6 66 | dqcpa114 copyabs -0E+6 -> 0E+6 67 | dqcpa115 copyabs 0.0000 -> 0.0000 68 | dqcpa116 copyabs -0.0000 -> 0.0000 69 | dqcpa117 copyabs 0E-141 -> 0E-141 70 | dqcpa118 copyabs -0E-141 -> 0E-141 71 | 72 | -- full coefficients, alternating bits 73 | dqcpa121 copyabs 2682682682682682682682682682682682 -> 2682682682682682682682682682682682 74 | dqcpa122 copyabs -2682682682682682682682682682682682 -> 2682682682682682682682682682682682 75 | dqcpa123 copyabs 1341341341341341341341341341341341 -> 1341341341341341341341341341341341 76 | dqcpa124 copyabs -1341341341341341341341341341341341 -> 1341341341341341341341341341341341 77 | 78 | -- Nmax, Nmin, Ntiny 79 | dqcpa131 copyabs 9.999999999999999999999999999999999E+6144 -> 9.999999999999999999999999999999999E+6144 80 | dqcpa132 copyabs 1E-6143 -> 1E-6143 81 | dqcpa133 copyabs 1.000000000000000000000000000000000E-6143 -> 1.000000000000000000000000000000000E-6143 82 | dqcpa134 copyabs 1E-6176 -> 1E-6176 83 | 84 | dqcpa135 copyabs -1E-6176 -> 1E-6176 85 | dqcpa136 copyabs -1.000000000000000000000000000000000E-6143 -> 1.000000000000000000000000000000000E-6143 86 | dqcpa137 copyabs -1E-6143 -> 1E-6143 87 | dqcpa138 copyabs -9.999999999999999999999999999999999E+6144 -> 9.999999999999999999999999999999999E+6144 88 | -------------------------------------------------------------------------------- /testdata/dqPlus.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- dqPlus.decTest -- decQuad 0+x -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | -- All operands and results are decQuads. 22 | extended: 1 23 | clamp: 1 24 | precision: 34 25 | maxExponent: 6144 26 | minExponent: -6143 27 | rounding: half_even 28 | 29 | -- Sanity check 30 | dqpls001 plus +7.50 -> 7.50 31 | 32 | -- Infinities 33 | dqpls011 plus Infinity -> Infinity 34 | dqpls012 plus -Infinity -> -Infinity 35 | 36 | -- NaNs, 0 payload 37 | ddqls021 plus NaN -> NaN 38 | ddqls022 plus -NaN -> -NaN 39 | ddqls023 plus sNaN -> NaN Invalid_operation 40 | ddqls024 plus -sNaN -> -NaN Invalid_operation 41 | 42 | -- NaNs, non-0 payload 43 | ddqls031 plus NaN13 -> NaN13 44 | ddqls032 plus -NaN13 -> -NaN13 45 | ddqls033 plus sNaN13 -> NaN13 Invalid_operation 46 | ddqls034 plus -sNaN13 -> -NaN13 Invalid_operation 47 | ddqls035 plus NaN70 -> NaN70 48 | ddqls036 plus -NaN70 -> -NaN70 49 | ddqls037 plus sNaN101 -> NaN101 Invalid_operation 50 | ddqls038 plus -sNaN101 -> -NaN101 Invalid_operation 51 | 52 | -- finites 53 | dqpls101 plus 7 -> 7 54 | dqpls102 plus -7 -> -7 55 | dqpls103 plus 75 -> 75 56 | dqpls104 plus -75 -> -75 57 | dqpls105 plus 7.50 -> 7.50 58 | dqpls106 plus -7.50 -> -7.50 59 | dqpls107 plus 7.500 -> 7.500 60 | dqpls108 plus -7.500 -> -7.500 61 | 62 | -- zeros 63 | dqpls111 plus 0 -> 0 64 | dqpls112 plus -0 -> 0 65 | dqpls113 plus 0E+4 -> 0E+4 66 | dqpls114 plus -0E+4 -> 0E+4 67 | dqpls115 plus 0.0000 -> 0.0000 68 | dqpls116 plus -0.0000 -> 0.0000 69 | dqpls117 plus 0E-141 -> 0E-141 70 | dqpls118 plus -0E-141 -> 0E-141 71 | 72 | -- full coefficients, alternating bits 73 | dqpls121 plus 2682682682682682682682682682682682 -> 2682682682682682682682682682682682 74 | dqpls122 plus -2682682682682682682682682682682682 -> -2682682682682682682682682682682682 75 | dqpls123 plus 1341341341341341341341341341341341 -> 1341341341341341341341341341341341 76 | dqpls124 plus -1341341341341341341341341341341341 -> -1341341341341341341341341341341341 77 | 78 | -- Nmax, Nmin, Ntiny 79 | dqpls131 plus 9.999999999999999999999999999999999E+6144 -> 9.999999999999999999999999999999999E+6144 80 | dqpls132 plus 1E-6143 -> 1E-6143 81 | dqpls133 plus 1.000000000000000000000000000000000E-6143 -> 1.000000000000000000000000000000000E-6143 82 | dqpls134 plus 1E-6176 -> 1E-6176 Subnormal 83 | 84 | dqpls135 plus -1E-6176 -> -1E-6176 Subnormal 85 | dqpls136 plus -1.000000000000000000000000000000000E-6143 -> -1.000000000000000000000000000000000E-6143 86 | dqpls137 plus -1E-6143 -> -1E-6143 87 | dqpls138 plus -9.999999999999999999999999999999999E+6144 -> -9.999999999999999999999999999999999E+6144 88 | -------------------------------------------------------------------------------- /testdata/dqMinus.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- dqMinus.decTest -- decQuad 0-x -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | -- All operands and results are decQuads. 22 | extended: 1 23 | clamp: 1 24 | precision: 34 25 | maxExponent: 6144 26 | minExponent: -6143 27 | rounding: half_even 28 | 29 | -- Sanity check 30 | dqmns001 minus +7.50 -> -7.50 31 | 32 | -- Infinities 33 | dqmns011 minus Infinity -> -Infinity 34 | dqmns012 minus -Infinity -> Infinity 35 | 36 | -- NaNs, 0 payload 37 | dqmns021 minus NaN -> NaN 38 | dqmns022 minus -NaN -> -NaN 39 | dqmns023 minus sNaN -> NaN Invalid_operation 40 | dqmns024 minus -sNaN -> -NaN Invalid_operation 41 | 42 | -- NaNs, non-0 payload 43 | dqmns031 minus NaN13 -> NaN13 44 | dqmns032 minus -NaN13 -> -NaN13 45 | dqmns033 minus sNaN13 -> NaN13 Invalid_operation 46 | dqmns034 minus -sNaN13 -> -NaN13 Invalid_operation 47 | dqmns035 minus NaN70 -> NaN70 48 | dqmns036 minus -NaN70 -> -NaN70 49 | dqmns037 minus sNaN101 -> NaN101 Invalid_operation 50 | dqmns038 minus -sNaN101 -> -NaN101 Invalid_operation 51 | 52 | -- finites 53 | dqmns101 minus 7 -> -7 54 | dqmns102 minus -7 -> 7 55 | dqmns103 minus 75 -> -75 56 | dqmns104 minus -75 -> 75 57 | dqmns105 minus 7.50 -> -7.50 58 | dqmns106 minus -7.50 -> 7.50 59 | dqmns107 minus 7.500 -> -7.500 60 | dqmns108 minus -7.500 -> 7.500 61 | 62 | -- zeros 63 | dqmns111 minus 0 -> 0 64 | dqmns112 minus -0 -> 0 65 | dqmns113 minus 0E+4 -> 0E+4 66 | dqmns114 minus -0E+4 -> 0E+4 67 | dqmns115 minus 0.0000 -> 0.0000 68 | dqmns116 minus -0.0000 -> 0.0000 69 | dqmns117 minus 0E-141 -> 0E-141 70 | dqmns118 minus -0E-141 -> 0E-141 71 | 72 | -- full coefficients, alternating bits 73 | dqmns121 minus 2682682682682682682682682682682682 -> -2682682682682682682682682682682682 74 | dqmns122 minus -2682682682682682682682682682682682 -> 2682682682682682682682682682682682 75 | dqmns123 minus 1341341341341341341341341341341341 -> -1341341341341341341341341341341341 76 | dqmns124 minus -1341341341341341341341341341341341 -> 1341341341341341341341341341341341 77 | 78 | -- Nmax, Nmin, Ntiny 79 | dqmns131 minus 9.999999999999999999999999999999999E+6144 -> -9.999999999999999999999999999999999E+6144 80 | dqmns132 minus 1E-6143 -> -1E-6143 81 | dqmns133 minus 1.000000000000000000000000000000000E-6143 -> -1.000000000000000000000000000000000E-6143 82 | dqmns134 minus 1E-6176 -> -1E-6176 Subnormal 83 | 84 | dqmns135 minus -1E-6176 -> 1E-6176 Subnormal 85 | dqmns136 minus -1.000000000000000000000000000000000E-6143 -> 1.000000000000000000000000000000000E-6143 86 | dqmns137 minus -1E-6143 -> 1E-6143 87 | dqmns138 minus -9.999999999999999999999999999999999E+6144 -> 9.999999999999999999999999999999999E+6144 88 | -------------------------------------------------------------------------------- /testdata/dqCopyNegate.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- dqCopyNegate.decTest -- quiet decQuad copy and negate -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | -- All operands and results are decQuads. 22 | extended: 1 23 | clamp: 1 24 | precision: 34 25 | maxExponent: 6144 26 | minExponent: -6143 27 | rounding: half_even 28 | 29 | -- Sanity check 30 | dqcpn001 copynegate +7.50 -> -7.50 31 | 32 | -- Infinities 33 | dqcpn011 copynegate Infinity -> -Infinity 34 | dqcpn012 copynegate -Infinity -> Infinity 35 | 36 | -- NaNs, 0 payload 37 | dqcpn021 copynegate NaN -> -NaN 38 | dqcpn022 copynegate -NaN -> NaN 39 | dqcpn023 copynegate sNaN -> -sNaN 40 | dqcpn024 copynegate -sNaN -> sNaN 41 | 42 | -- NaNs, non-0 payload 43 | dqcpn031 copynegate NaN13 -> -NaN13 44 | dqcpn032 copynegate -NaN13 -> NaN13 45 | dqcpn033 copynegate sNaN13 -> -sNaN13 46 | dqcpn034 copynegate -sNaN13 -> sNaN13 47 | dqcpn035 copynegate NaN70 -> -NaN70 48 | dqcpn036 copynegate -NaN70 -> NaN70 49 | dqcpn037 copynegate sNaN101 -> -sNaN101 50 | dqcpn038 copynegate -sNaN101 -> sNaN101 51 | 52 | -- finites 53 | dqcpn101 copynegate 7 -> -7 54 | dqcpn102 copynegate -7 -> 7 55 | dqcpn103 copynegate 75 -> -75 56 | dqcpn104 copynegate -75 -> 75 57 | dqcpn105 copynegate 7.50 -> -7.50 58 | dqcpn106 copynegate -7.50 -> 7.50 59 | dqcpn107 copynegate 7.500 -> -7.500 60 | dqcpn108 copynegate -7.500 -> 7.500 61 | 62 | -- zeros 63 | dqcpn111 copynegate 0 -> -0 64 | dqcpn112 copynegate -0 -> 0 65 | dqcpn113 copynegate 0E+4 -> -0E+4 66 | dqcpn114 copynegate -0E+4 -> 0E+4 67 | dqcpn115 copynegate 0.0000 -> -0.0000 68 | dqcpn116 copynegate -0.0000 -> 0.0000 69 | dqcpn117 copynegate 0E-141 -> -0E-141 70 | dqcpn118 copynegate -0E-141 -> 0E-141 71 | 72 | -- full coefficients, alternating bits 73 | dqcpn121 copynegate 2682682682682682682682682682682682 -> -2682682682682682682682682682682682 74 | dqcpn122 copynegate -2682682682682682682682682682682682 -> 2682682682682682682682682682682682 75 | dqcpn123 copynegate 1341341341341341341341341341341341 -> -1341341341341341341341341341341341 76 | dqcpn124 copynegate -1341341341341341341341341341341341 -> 1341341341341341341341341341341341 77 | 78 | -- Nmax, Nmin, Ntiny 79 | dqcpn131 copynegate 9.999999999999999999999999999999999E+6144 -> -9.999999999999999999999999999999999E+6144 80 | dqcpn132 copynegate 1E-6143 -> -1E-6143 81 | dqcpn133 copynegate 1.000000000000000000000000000000000E-6143 -> -1.000000000000000000000000000000000E-6143 82 | dqcpn134 copynegate 1E-6176 -> -1E-6176 83 | 84 | dqcpn135 copynegate -1E-6176 -> 1E-6176 85 | dqcpn136 copynegate -1.000000000000000000000000000000000E-6143 -> 1.000000000000000000000000000000000E-6143 86 | dqcpn137 copynegate -1E-6143 -> 1E-6143 87 | dqcpn138 copynegate -9.999999999999999999999999999999999E+6144 -> 9.999999999999999999999999999999999E+6144 88 | -------------------------------------------------------------------------------- /decnumber-sys/decnumber/decimal32.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------ */ 2 | /* Decimal 32-bit format module header */ 3 | /* ------------------------------------------------------------------ */ 4 | /* Copyright (c) IBM Corporation, 2000, 2006. All rights reserved. */ 5 | /* */ 6 | /* This software is made available under the terms of the */ 7 | /* ICU License -- ICU 1.8.1 and later. */ 8 | /* */ 9 | /* The description and User's Guide ("The decNumber C Library") for */ 10 | /* this software is called decNumber.pdf. This document is */ 11 | /* available, together with arithmetic and format specifications, */ 12 | /* testcases, and Web links, on the General Decimal Arithmetic page. */ 13 | /* */ 14 | /* Please send comments, suggestions, and corrections to the author: */ 15 | /* mfc@uk.ibm.com */ 16 | /* Mike Cowlishaw, IBM Fellow */ 17 | /* IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK */ 18 | /* ------------------------------------------------------------------ */ 19 | 20 | #if !defined(DECIMAL32) 21 | #define DECIMAL32 22 | #define DEC32NAME "decimal32" /* Short name */ 23 | #define DEC32FULLNAME "Decimal 32-bit Number" /* Verbose name */ 24 | #define DEC32AUTHOR "Mike Cowlishaw" /* Who to blame */ 25 | 26 | /* parameters for decimal32s */ 27 | #define DECIMAL32_Bytes 4 /* length */ 28 | #define DECIMAL32_Pmax 7 /* maximum precision (digits) */ 29 | #define DECIMAL32_Emax 96 /* maximum adjusted exponent */ 30 | #define DECIMAL32_Emin -95 /* minimum adjusted exponent */ 31 | #define DECIMAL32_Bias 101 /* bias for the exponent */ 32 | #define DECIMAL32_String 15 /* maximum string length, +1 */ 33 | #define DECIMAL32_EconL 6 /* exp. continuation length */ 34 | /* highest biased exponent (Elimit-1) */ 35 | #define DECIMAL32_Ehigh (DECIMAL32_Emax+DECIMAL32_Bias-DECIMAL32_Pmax+1) 36 | 37 | /* check enough digits, if pre-defined */ 38 | #if defined(DECNUMDIGITS) 39 | #if (DECNUMDIGITS=7 for safe use 41 | #endif 42 | #endif 43 | 44 | #ifndef DECNUMDIGITS 45 | #define DECNUMDIGITS DECIMAL32_Pmax /* size if not already defined*/ 46 | #endif 47 | #ifndef DECNUMBER 48 | #include "decNumber.h" /* context and number library */ 49 | #endif 50 | 51 | /* Decimal 32-bit type, accessible by bytes */ 52 | typedef union { 53 | uint8_t bytes[DECIMAL32_Bytes]; /* decimal32: 1, 5, 6, 20 bits*/ 54 | uint16_t shorts[DECIMAL32_Bytes/2]; 55 | uint32_t words[DECIMAL32_Bytes/4]; 56 | } decimal32; 57 | 58 | /* special values [top byte excluding sign bit; last two bits are */ 59 | /* don't-care for Infinity on input, last bit don't-care for NaN] */ 60 | #if !defined(DECIMAL_NaN) 61 | #define DECIMAL_NaN 0x7c /* 0 11111 00 NaN */ 62 | #define DECIMAL_sNaN 0x7e /* 0 11111 10 sNaN */ 63 | #define DECIMAL_Inf 0x78 /* 0 11110 00 Infinity */ 64 | #endif 65 | 66 | /* ---------------------------------------------------------------- */ 67 | /* Routines */ 68 | /* ---------------------------------------------------------------- */ 69 | /* String conversions */ 70 | decimal32 * decimal32FromString(decimal32 *, const char *, decContext *); 71 | char * decimal32ToString(const decimal32 *, char *); 72 | char * decimal32ToEngString(const decimal32 *, char *); 73 | 74 | /* decNumber conversions */ 75 | decimal32 * decimal32FromNumber(decimal32 *, const decNumber *, 76 | decContext *); 77 | decNumber * decimal32ToNumber(const decimal32 *, decNumber *); 78 | 79 | /* Format-dependent utilities */ 80 | uint32_t decimal32IsCanonical(const decimal32 *); 81 | decimal32 * decimal32Canonical(decimal32 *, const decimal32 *); 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /decnumber-sys/decnumber/decimal128.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------ */ 2 | /* Decimal 128-bit format module header */ 3 | /* ------------------------------------------------------------------ */ 4 | /* Copyright (c) IBM Corporation, 2000, 2005. All rights reserved. */ 5 | /* */ 6 | /* This software is made available under the terms of the */ 7 | /* ICU License -- ICU 1.8.1 and later. */ 8 | /* */ 9 | /* The description and User's Guide ("The decNumber C Library") for */ 10 | /* this software is called decNumber.pdf. This document is */ 11 | /* available, together with arithmetic and format specifications, */ 12 | /* testcases, and Web links, on the General Decimal Arithmetic page. */ 13 | /* */ 14 | /* Please send comments, suggestions, and corrections to the author: */ 15 | /* mfc@uk.ibm.com */ 16 | /* Mike Cowlishaw, IBM Fellow */ 17 | /* IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK */ 18 | /* ------------------------------------------------------------------ */ 19 | 20 | #if !defined(DECIMAL128) 21 | #define DECIMAL128 22 | #define DEC128NAME "decimal128" /* Short name */ 23 | #define DEC128FULLNAME "Decimal 128-bit Number" /* Verbose name */ 24 | #define DEC128AUTHOR "Mike Cowlishaw" /* Who to blame */ 25 | 26 | /* parameters for decimal128s */ 27 | #define DECIMAL128_Bytes 16 /* length */ 28 | #define DECIMAL128_Pmax 34 /* maximum precision (digits) */ 29 | #define DECIMAL128_Emax 6144 /* maximum adjusted exponent */ 30 | #define DECIMAL128_Emin -6143 /* minimum adjusted exponent */ 31 | #define DECIMAL128_Bias 6176 /* bias for the exponent */ 32 | #define DECIMAL128_String 43 /* maximum string length, +1 */ 33 | #define DECIMAL128_EconL 12 /* exp. continuation length */ 34 | /* highest biased exponent (Elimit-1) */ 35 | #define DECIMAL128_Ehigh (DECIMAL128_Emax+DECIMAL128_Bias-DECIMAL128_Pmax+1) 36 | 37 | /* check enough digits, if pre-defined */ 38 | #if defined(DECNUMDIGITS) 39 | #if (DECNUMDIGITS=34 for safe use 41 | #endif 42 | #endif 43 | 44 | #ifndef DECNUMDIGITS 45 | #define DECNUMDIGITS DECIMAL128_Pmax /* size if not already defined*/ 46 | #endif 47 | #ifndef DECNUMBER 48 | #include "decNumber.h" /* context and number library */ 49 | #endif 50 | 51 | /* Decimal 128-bit type, accessible by bytes */ 52 | typedef union { 53 | uint8_t bytes[DECIMAL128_Bytes]; /* decimal128: 1, 5, 12, 110 bits*/ 54 | uint16_t shorts[DECIMAL128_Bytes/2]; 55 | uint32_t words[DECIMAL128_Bytes/4]; 56 | #if DECUSE64 57 | uint64_t longs[DECIMAL128_Bytes/8]; 58 | #endif 59 | } decimal128; 60 | 61 | /* special values [top byte excluding sign bit; last two bits are */ 62 | /* don't-care for Infinity on input, last bit don't-care for NaN] */ 63 | #if !defined(DECIMAL_NaN) 64 | #define DECIMAL_NaN 0x7c /* 0 11111 00 NaN */ 65 | #define DECIMAL_sNaN 0x7e /* 0 11111 10 sNaN */ 66 | #define DECIMAL_Inf 0x78 /* 0 11110 00 Infinity */ 67 | #endif 68 | 69 | /* ---------------------------------------------------------------- */ 70 | /* Routines */ 71 | /* ---------------------------------------------------------------- */ 72 | /* String conversions */ 73 | decimal128 * decimal128FromString(decimal128 *, const char *, decContext *); 74 | char * decimal128ToString(const decimal128 *, char *); 75 | char * decimal128ToEngString(const decimal128 *, char *); 76 | 77 | /* decNumber conversions */ 78 | decimal128 * decimal128FromNumber(decimal128 *, const decNumber *, 79 | decContext *); 80 | decNumber * decimal128ToNumber(const decimal128 *, decNumber *); 81 | 82 | /* Format-dependent utilities */ 83 | uint32_t decimal128IsCanonical(const decimal128 *); 84 | decimal128 * decimal128Canonical(decimal128 *, const decimal128 *); 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /decnumber-sys/decnumber/decimal64.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------ */ 2 | /* Decimal 64-bit format module header */ 3 | /* ------------------------------------------------------------------ */ 4 | /* Copyright (c) IBM Corporation, 2000, 2005. All rights reserved. */ 5 | /* */ 6 | /* This software is made available under the terms of the */ 7 | /* ICU License -- ICU 1.8.1 and later. */ 8 | /* */ 9 | /* The description and User's Guide ("The decNumber C Library") for */ 10 | /* this software is called decNumber.pdf. This document is */ 11 | /* available, together with arithmetic and format specifications, */ 12 | /* testcases, and Web links, on the General Decimal Arithmetic page. */ 13 | /* */ 14 | /* Please send comments, suggestions, and corrections to the author: */ 15 | /* mfc@uk.ibm.com */ 16 | /* Mike Cowlishaw, IBM Fellow */ 17 | /* IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK */ 18 | /* ------------------------------------------------------------------ */ 19 | 20 | #if !defined(DECIMAL64) 21 | #define DECIMAL64 22 | #define DEC64NAME "decimal64" /* Short name */ 23 | #define DEC64FULLNAME "Decimal 64-bit Number" /* Verbose name */ 24 | #define DEC64AUTHOR "Mike Cowlishaw" /* Who to blame */ 25 | 26 | 27 | /* parameters for decimal64s */ 28 | #define DECIMAL64_Bytes 8 /* length */ 29 | #define DECIMAL64_Pmax 16 /* maximum precision (digits) */ 30 | #define DECIMAL64_Emax 384 /* maximum adjusted exponent */ 31 | #define DECIMAL64_Emin -383 /* minimum adjusted exponent */ 32 | #define DECIMAL64_Bias 398 /* bias for the exponent */ 33 | #define DECIMAL64_String 24 /* maximum string length, +1 */ 34 | #define DECIMAL64_EconL 8 /* exp. continuation length */ 35 | /* highest biased exponent (Elimit-1) */ 36 | #define DECIMAL64_Ehigh (DECIMAL64_Emax+DECIMAL64_Bias-DECIMAL64_Pmax+1) 37 | 38 | /* check enough digits, if pre-defined */ 39 | #if defined(DECNUMDIGITS) 40 | #if (DECNUMDIGITS=16 for safe use 42 | #endif 43 | #endif 44 | 45 | 46 | #ifndef DECNUMDIGITS 47 | #define DECNUMDIGITS DECIMAL64_Pmax /* size if not already defined*/ 48 | #endif 49 | #ifndef DECNUMBER 50 | #include "decNumber.h" /* context and number library */ 51 | #endif 52 | 53 | /* Decimal 64-bit type, accessible by bytes */ 54 | typedef union { 55 | uint8_t bytes[DECIMAL64_Bytes]; /* decimal64: 1, 5, 8, 50 bits*/ 56 | uint16_t shorts[DECIMAL64_Bytes/2]; 57 | uint32_t words[DECIMAL64_Bytes/4]; 58 | #if DECUSE64 59 | uint64_t longs[DECIMAL64_Bytes/8]; 60 | #endif 61 | } decimal64; 62 | 63 | /* special values [top byte excluding sign bit; last two bits are */ 64 | /* don't-care for Infinity on input, last bit don't-care for NaN] */ 65 | #if !defined(DECIMAL_NaN) 66 | #define DECIMAL_NaN 0x7c /* 0 11111 00 NaN */ 67 | #define DECIMAL_sNaN 0x7e /* 0 11111 10 sNaN */ 68 | #define DECIMAL_Inf 0x78 /* 0 11110 00 Infinity */ 69 | #endif 70 | 71 | /* ---------------------------------------------------------------- */ 72 | /* Routines */ 73 | /* ---------------------------------------------------------------- */ 74 | /* String conversions */ 75 | decimal64 * decimal64FromString(decimal64 *, const char *, decContext *); 76 | char * decimal64ToString(const decimal64 *, char *); 77 | char * decimal64ToEngString(const decimal64 *, char *); 78 | 79 | /* decNumber conversions */ 80 | decimal64 * decimal64FromNumber(decimal64 *, const decNumber *, 81 | decContext *); 82 | decNumber * decimal64ToNumber(const decimal64 *, decNumber *); 83 | 84 | /* Format-dependent utilities */ 85 | uint32_t decimal64IsCanonical(const decimal64 *); 86 | decimal64 * decimal64Canonical(decimal64 *, const decimal64 *); 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /dectest/src/main.rs: -------------------------------------------------------------------------------- 1 | // Copyright Materialize, Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License in the LICENSE file at the 6 | // root of this repository, or online at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | use std::env; 17 | use std::error::Error; 18 | use std::path::PathBuf; 19 | use std::process; 20 | 21 | use dectest::ast; 22 | use dectest::backend::{Decimal128Backend, Decimal32Backend, Decimal64Backend, DecimalBackend}; 23 | use dectest::parse; 24 | use dectest::run::{self, Outcome, Report}; 25 | 26 | fn main() { 27 | if let Err(e) = run() { 28 | eprintln!("error: {}", e); 29 | process::exit(1); 30 | } 31 | } 32 | 33 | fn run() -> Result<(), Box> { 34 | let mut paths = vec![]; 35 | let mut verbose = false; 36 | let mut backend = BackendSpec::Decimal128; 37 | let mut args = env::args().into_iter().skip(1); 38 | while let Some(arg) = args.next() { 39 | match arg.as_str() { 40 | "-v" => verbose = true, 41 | "-b" => match args.next().as_deref() { 42 | None => return Err("-b flag requires a value".into()), 43 | Some("decimal") => backend = BackendSpec::Decimal, 44 | Some("decimal32") => backend = BackendSpec::Decimal32, 45 | Some("decimal64") => backend = BackendSpec::Decimal64, 46 | Some("decimal128") => backend = BackendSpec::Decimal128, 47 | Some(b) => return Err(format!("unknown backend \"{}\"", b).into()), 48 | }, 49 | _ => paths.push(PathBuf::from(arg)), 50 | } 51 | } 52 | if paths.is_empty() { 53 | return Err("usage: dectest [-v] [-b BACKEND] ...".into()); 54 | } 55 | 56 | let mut reporter = ConsoleReporter::new(verbose); 57 | 58 | for path in paths { 59 | let file = parse::parse_file(&path)?; 60 | match backend { 61 | BackendSpec::Decimal => run::run_file::(&mut reporter, &file)?, 62 | BackendSpec::Decimal32 => run::run_file::(&mut reporter, &file)?, 63 | BackendSpec::Decimal64 => run::run_file::(&mut reporter, &file)?, 64 | BackendSpec::Decimal128 => run::run_file::(&mut reporter, &file)?, 65 | } 66 | } 67 | 68 | println!("PASS {}", reporter.passes); 69 | println!("FAIL {}", reporter.failures); 70 | println!("SKIP {}", reporter.skips); 71 | 72 | if reporter.failures > 0 { 73 | process::exit(1) 74 | } 75 | Ok(()) 76 | } 77 | 78 | enum BackendSpec { 79 | Decimal, 80 | Decimal32, 81 | Decimal64, 82 | Decimal128, 83 | } 84 | 85 | struct ConsoleReporter { 86 | failures: usize, 87 | passes: usize, 88 | skips: usize, 89 | verbose: bool, 90 | } 91 | 92 | impl ConsoleReporter { 93 | fn new(verbose: bool) -> ConsoleReporter { 94 | ConsoleReporter { 95 | failures: 0, 96 | passes: 0, 97 | skips: 0, 98 | verbose, 99 | } 100 | } 101 | } 102 | 103 | impl Report for ConsoleReporter { 104 | fn start_file(&mut self, file: &ast::File) { 105 | println!("==> {}", file.path.display()) 106 | } 107 | 108 | fn finish_file(&mut self) {} 109 | 110 | fn start_test(&mut self, test: &ast::Test) { 111 | if self.verbose { 112 | print!("{} {} -> {}", test.id, test.operation, test.result); 113 | if !test.conditions.is_empty() { 114 | let conditions: Vec<_> = test.conditions.iter().map(|c| c.to_string()).collect(); 115 | print!(" ({})", conditions.join(", ")); 116 | } 117 | println!(); 118 | } else { 119 | print!("{} ", test.id); 120 | } 121 | } 122 | 123 | fn finish_test(&mut self, outcome: Outcome) { 124 | match outcome { 125 | Outcome::Passed => self.passes += 1, 126 | Outcome::Failed { .. } => self.failures += 1, 127 | Outcome::Skipped => self.skips += 1, 128 | } 129 | match outcome { 130 | Outcome::Passed => println!("PASS"), 131 | Outcome::Failed { cause } => println!("FAIL: {}", cause), 132 | Outcome::Skipped => println!("SKIP"), 133 | } 134 | if self.verbose { 135 | println!() 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /dec/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright Materialize, Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License in the LICENSE file at the 6 | // root of this repository, or online at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //! dec is a decimal arithmetic library for Rust. 17 | //! 18 | //! # Introduction 19 | //! 20 | //! From the [Decimal Arithmetic FAQ][faq]: 21 | //! 22 | //! > Most people in the world use decimal (base 10) arithmetic. When large or 23 | //! > small values are needed, exponents which are powers of ten are used. 24 | //! > However, most computers have only binary (base two) arithmetic, and when 25 | //! > exponents are used (in floating-poing numbers) they are powers of two. 26 | //! > 27 | //! > Binary floating-point numbers can only approximate common decimal numbers. 28 | //! > The value 0.1, for example, would need an infinitely recurring binary 29 | //! > fraction. In contrast, a decimal number system can represent 0.1 exactly, 30 | //! > as one tenth (that is, 10-1). Consequently, binary 31 | //! > floating-point cannot be used for financial calculations, or indeed for 32 | //! > any calculations where the results achieved are required to match those 33 | //! > which might be calculated by hand. 34 | //! 35 | //! dec is an implementation of the General Decimal Arithmetic standard, which 36 | //! precisely describes both a limited-precision floating-point decimal 37 | //! arithmetic and an arbitrary precision floating-point decimal arithmetic. 38 | //! 39 | //! The latest draft of the standard is available online at 40 | //! . The floating-point 41 | //! arithmetic additionally conforms to the IEEE 754-2008 specification, but 42 | //! this specification is not freely available. 43 | //! 44 | //! # Details 45 | //! 46 | //! dec is a safe Rust API atop the C reference implementation, [libdecnumber]. 47 | //! Unsafe C bindings to libdecnumber are available in the [decnumber-sys] 48 | //! crate. 49 | //! 50 | //! The main types exposed by this library are as follows: 51 | //! 52 | //! * [`Decimal32`], a 32-bit decimal floating-point representation which 53 | //! provides 7 decimal digits of precision in a compressed format. This type 54 | //! is intended for storage and interchange only and so does not support any 55 | //! arithmetic functions. 56 | //! 57 | //! * [`Decimal64`], a 64-bit decimal floating-point representation which 58 | //! provides 16 decimal digits of precision in a compressed format along with 59 | //! various arithmetic functions. 60 | //! 61 | //! * [`Decimal128`], a 128-bit decimal floating-point representation which 62 | //! provides 34 decimal digits of precision in a compressed format along with 63 | //! various arithmetic functions. 64 | //! 65 | //! * [`Decimal`], a decimal representation whose precision is configurable via 66 | //! its generic `N` parameter. 67 | //! 68 | //! * [`Context`], which hosts most of the actual functions on the above types. 69 | //! A context configures the behavior of the various operations (e.g., 70 | //! rounding mode) and accumulates exceptional conditions (e.g., overflow). 71 | //! 72 | //! # Examples 73 | //! 74 | //! The following example demonstrates the basic usage of the library: 75 | //! 76 | //! ``` 77 | //! # use std::error::Error; 78 | //! use dec::Decimal128; 79 | //! 80 | //! let x: Decimal128 = ".1".parse()?; 81 | //! let y: Decimal128 = ".2".parse()?; 82 | //! let z: Decimal128 = ".3".parse()?; 83 | //! 84 | //! assert_eq!(x + y, z); 85 | //! assert_eq!((x + y + z).to_string(), "0.6"); 86 | //! 87 | //! # Ok::<_, Box>(()) 88 | //! ``` 89 | //! 90 | //! [faq]: http://speleotrove.com/decimal/decifaq.html 91 | //! [libdecnumber]: http://speleotrove.com/decimal/decarith.html 92 | //! [decnumber-sys]: https://docs.rs/decnumber-sys 93 | 94 | #![deny(missing_debug_implementations, missing_docs)] 95 | #![cfg_attr(docsrs, feature(doc_cfg))] 96 | 97 | mod context; 98 | #[macro_use] 99 | mod conv; 100 | mod decimal; 101 | mod decimal128; 102 | mod decimal32; 103 | mod decimal64; 104 | mod error; 105 | mod ordered; 106 | #[cfg(tests)] 107 | mod tests; 108 | 109 | pub use context::{Class, Context, Rounding, Status}; 110 | #[cfg(feature = "serde")] 111 | pub use decimal::serde_decimal_from_non_float_primitives; 112 | pub use decimal::Decimal; 113 | pub use decimal128::Decimal128; 114 | pub use decimal32::Decimal32; 115 | pub use decimal64::Decimal64; 116 | pub use error::{ 117 | InvalidExponentError, InvalidPrecisionError, ParseDecimalError, TryFromDecimalError, 118 | }; 119 | pub use ordered::OrderedDecimal; 120 | -------------------------------------------------------------------------------- /decnumber-sys/decnumber/decSingle.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------ */ 2 | /* decSingle.h -- Decimal 32-bit format module header */ 3 | /* ------------------------------------------------------------------ */ 4 | /* Copyright (c) IBM Corporation, 2000, 2008. All rights reserved. */ 5 | /* */ 6 | /* This software is made available under the terms of the */ 7 | /* ICU License -- ICU 1.8.1 and later. */ 8 | /* */ 9 | /* The description and User's Guide ("The decNumber C Library") for */ 10 | /* this software is included in the package as decNumber.pdf. This */ 11 | /* document is also available in HTML, together with specifications, */ 12 | /* testcases, and Web links, on the General Decimal Arithmetic page. */ 13 | /* */ 14 | /* Please send comments, suggestions, and corrections to the author: */ 15 | /* mfc@uk.ibm.com */ 16 | /* Mike Cowlishaw, IBM Fellow */ 17 | /* IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK */ 18 | /* ------------------------------------------------------------------ */ 19 | 20 | #if !defined(DECSINGLE) 21 | #define DECSINGLE 22 | 23 | #define DECSINGLENAME "decSingle" /* Short name */ 24 | #define DECSINGLETITLE "Decimal 32-bit datum" /* Verbose name */ 25 | #define DECSINGLEAUTHOR "Mike Cowlishaw" /* Who to blame */ 26 | 27 | /* parameters for decSingles */ 28 | #define DECSINGLE_Bytes 4 /* length */ 29 | #define DECSINGLE_Pmax 7 /* maximum precision (digits) */ 30 | #define DECSINGLE_Emin -95 /* minimum adjusted exponent */ 31 | #define DECSINGLE_Emax 96 /* maximum adjusted exponent */ 32 | #define DECSINGLE_EmaxD 3 /* maximum exponent digits */ 33 | #define DECSINGLE_Bias 101 /* bias for the exponent */ 34 | #define DECSINGLE_String 16 /* maximum string length, +1 */ 35 | #define DECSINGLE_EconL 6 /* exponent continuation length */ 36 | #define DECSINGLE_Declets 2 /* count of declets */ 37 | /* highest biased exponent (Elimit-1) */ 38 | #define DECSINGLE_Ehigh (DECSINGLE_Emax + DECSINGLE_Bias - (DECSINGLE_Pmax-1)) 39 | 40 | /* Required includes */ 41 | #include "decContext.h" 42 | #include "decQuad.h" 43 | #include "decDouble.h" 44 | 45 | /* The decSingle decimal 32-bit type, accessible by all sizes */ 46 | typedef union { 47 | uint8_t bytes[DECSINGLE_Bytes]; /* fields: 1, 5, 6, 20 bits */ 48 | uint16_t shorts[DECSINGLE_Bytes/2]; 49 | uint32_t words[DECSINGLE_Bytes/4]; 50 | } decSingle; 51 | 52 | /* ---------------------------------------------------------------- */ 53 | /* Routines -- implemented as decFloat routines in common files */ 54 | /* ---------------------------------------------------------------- */ 55 | 56 | /* Utilities (binary argument(s) or result, extractors, etc.) */ 57 | extern decSingle * decSingleFromBCD(decSingle *, int32_t, const uint8_t *, int32_t); 58 | extern decSingle * decSingleFromPacked(decSingle *, int32_t, const uint8_t *); 59 | extern decSingle * decSingleFromPackedChecked(decSingle *, int32_t, const uint8_t *); 60 | extern decSingle * decSingleFromString(decSingle *, const char *, decContext *); 61 | extern decSingle * decSingleFromWider(decSingle *, const decDouble *, decContext *); 62 | extern int32_t decSingleGetCoefficient(const decSingle *, uint8_t *); 63 | extern int32_t decSingleGetExponent(const decSingle *); 64 | extern decSingle * decSingleSetCoefficient(decSingle *, const uint8_t *, int32_t); 65 | extern decSingle * decSingleSetExponent(decSingle *, decContext *, int32_t); 66 | extern void decSingleShow(const decSingle *, const char *); 67 | extern int32_t decSingleToBCD(const decSingle *, int32_t *, uint8_t *); 68 | extern char * decSingleToEngString(const decSingle *, char *); 69 | extern int32_t decSingleToPacked(const decSingle *, int32_t *, uint8_t *); 70 | extern char * decSingleToString(const decSingle *, char *); 71 | extern decDouble * decSingleToWider(const decSingle *, decDouble *); 72 | extern decSingle * decSingleZero(decSingle *); 73 | 74 | /* (No Arithmetic routines for decSingle) */ 75 | 76 | /* Non-computational */ 77 | extern uint32_t decSingleRadix(const decSingle *); 78 | extern const char * decSingleVersion(void); 79 | 80 | /* decNumber conversions; these are implemented as macros so as not */ 81 | /* to force a dependency on decimal32 and decNumber in decSingle. */ 82 | /* decSingleFromNumber returns a decimal32 * to avoid warnings. */ 83 | #define decSingleToNumber(dq, dn) decimal32ToNumber((decimal32 *)(dq), dn) 84 | #define decSingleFromNumber(dq, dn, set) decimal32FromNumber((decimal32 *)(dq), dn, set) 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /dec/tests/serde.rs: -------------------------------------------------------------------------------- 1 | // Copyright Materialize, Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License in the LICENSE file at the 6 | // root of this repository, or online at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | use std::convert::TryFrom; 16 | use std::str::FromStr; 17 | 18 | use serde::{Deserialize, Serialize}; 19 | use serde_json::json; 20 | use serde_test::{assert_tokens, Token}; 21 | 22 | use dec::{Context, Decimal}; 23 | 24 | #[test] 25 | fn test_serde() { 26 | const N: usize = 12; 27 | let mut cx = Context::>::default(); 28 | let d = cx.parse("-12.34").unwrap(); 29 | 30 | assert_tokens( 31 | &d, 32 | &[ 33 | Token::Struct { 34 | name: "Decimal", 35 | len: 4, 36 | }, 37 | Token::Str("digits"), 38 | Token::U32(4), 39 | Token::Str("exponent"), 40 | Token::I32(-2), 41 | Token::Str("bits"), 42 | // This is equal to decnumber_sys::DECNEG 43 | Token::U8(128), 44 | Token::Str("lsu"), 45 | Token::Seq { len: Some(12) }, 46 | Token::U16(234), 47 | Token::U16(1), 48 | Token::U16(0), 49 | Token::U16(0), 50 | Token::U16(0), 51 | Token::U16(0), 52 | Token::U16(0), 53 | Token::U16(0), 54 | Token::U16(0), 55 | Token::U16(0), 56 | Token::U16(0), 57 | Token::U16(0), 58 | Token::SeqEnd, 59 | Token::StructEnd, 60 | ], 61 | ); 62 | 63 | let d = cx 64 | .parse("1234567890123456789012345678901234567890") 65 | .unwrap(); 66 | 67 | assert_tokens( 68 | &d, 69 | &[ 70 | Token::Struct { 71 | name: "Decimal", 72 | len: 4, 73 | }, 74 | Token::Str("digits"), 75 | Token::U32(36), 76 | Token::Str("exponent"), 77 | Token::I32(4), 78 | Token::Str("bits"), 79 | Token::U8(0), 80 | Token::Str("lsu"), 81 | Token::Seq { len: Some(12) }, 82 | Token::U16(457), 83 | Token::U16(123), 84 | Token::U16(890), 85 | Token::U16(567), 86 | Token::U16(234), 87 | Token::U16(901), 88 | Token::U16(678), 89 | Token::U16(345), 90 | Token::U16(012), 91 | Token::U16(789), 92 | Token::U16(456), 93 | Token::U16(123), 94 | Token::SeqEnd, 95 | Token::StructEnd, 96 | ], 97 | ); 98 | 99 | for (json, err) in vec![ 100 | ( 101 | json!(1i32), 102 | "invalid type: integer `1`, expected struct Decimal", 103 | ), 104 | ( 105 | json!(0.5f32), 106 | "invalid type: floating point `0.5`, expected struct Decimal", 107 | ), 108 | ( 109 | json!("-1"), 110 | "invalid type: string \"-1\", expected struct Decimal", 111 | ), 112 | ] { 113 | assert_eq!( 114 | serde_json::from_value::>(json) 115 | .unwrap_err() 116 | .to_string(), 117 | err 118 | ); 119 | } 120 | 121 | #[repr(transparent)] 122 | #[derive(Debug, PartialEq, PartialOrd, Deserialize, Serialize)] 123 | pub struct PrimitiveDeserializableDecimal( 124 | #[serde(with = "dec::serde_decimal_from_non_float_primitives")] pub Decimal, 125 | ); 126 | 127 | for (json, dec) in vec![ 128 | (r#"-1"#, Decimal::try_from(-1i32).unwrap()), 129 | (r#""6.0E+2""#, Decimal::from_str("6.0E+2").unwrap()), 130 | ] { 131 | let deserialized_value: PrimitiveDeserializableDecimal = 132 | serde_json::from_str(json).expect("deserialization works"); 133 | assert_eq!(deserialized_value.0, dec); 134 | } 135 | 136 | // Ensure incompatible values do not work. 137 | for (json, err) in vec![ 138 | ( 139 | r#"true"#, 140 | "invalid type: boolean `true`, expected struct Decimal or compatible primitive at line 1 column 4", 141 | ), 142 | ( 143 | r#"0.5"#, 144 | "invalid type: floating point `0.5`, expected struct Decimal or compatible primitive at line 1 column 3", 145 | ), 146 | ] { 147 | assert_eq!( 148 | serde_json::from_str::>(json) 149 | .unwrap_err() 150 | .to_string(), 151 | err 152 | ); 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /testdata/ddAbs.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- ddAbs.decTest -- decDouble absolute value, heeding sNaN -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | precision: 16 22 | maxExponent: 384 23 | minExponent: -383 24 | extended: 1 25 | clamp: 1 26 | rounding: half_even 27 | 28 | ddabs001 abs '1' -> '1' 29 | ddabs002 abs '-1' -> '1' 30 | ddabs003 abs '1.00' -> '1.00' 31 | ddabs004 abs '-1.00' -> '1.00' 32 | ddabs005 abs '0' -> '0' 33 | ddabs006 abs '0.00' -> '0.00' 34 | ddabs007 abs '00.0' -> '0.0' 35 | ddabs008 abs '00.00' -> '0.00' 36 | ddabs009 abs '00' -> '0' 37 | 38 | ddabs010 abs '-2' -> '2' 39 | ddabs011 abs '2' -> '2' 40 | ddabs012 abs '-2.00' -> '2.00' 41 | ddabs013 abs '2.00' -> '2.00' 42 | ddabs014 abs '-0' -> '0' 43 | ddabs015 abs '-0.00' -> '0.00' 44 | ddabs016 abs '-00.0' -> '0.0' 45 | ddabs017 abs '-00.00' -> '0.00' 46 | ddabs018 abs '-00' -> '0' 47 | 48 | ddabs020 abs '-2000000' -> '2000000' 49 | ddabs021 abs '2000000' -> '2000000' 50 | 51 | ddabs030 abs '+0.1' -> '0.1' 52 | ddabs031 abs '-0.1' -> '0.1' 53 | ddabs032 abs '+0.01' -> '0.01' 54 | ddabs033 abs '-0.01' -> '0.01' 55 | ddabs034 abs '+0.001' -> '0.001' 56 | ddabs035 abs '-0.001' -> '0.001' 57 | ddabs036 abs '+0.000001' -> '0.000001' 58 | ddabs037 abs '-0.000001' -> '0.000001' 59 | ddabs038 abs '+0.000000000001' -> '1E-12' 60 | ddabs039 abs '-0.000000000001' -> '1E-12' 61 | 62 | -- examples from decArith 63 | ddabs040 abs '2.1' -> '2.1' 64 | ddabs041 abs '-100' -> '100' 65 | ddabs042 abs '101.5' -> '101.5' 66 | ddabs043 abs '-101.5' -> '101.5' 67 | 68 | -- more fixed, potential LHS swaps/overlays if done by subtract 0 69 | ddabs060 abs '-56267E-10' -> '0.0000056267' 70 | ddabs061 abs '-56267E-5' -> '0.56267' 71 | ddabs062 abs '-56267E-2' -> '562.67' 72 | ddabs063 abs '-56267E-1' -> '5626.7' 73 | ddabs065 abs '-56267E-0' -> '56267' 74 | 75 | -- subnormals and underflow 76 | 77 | -- long operand tests 78 | ddabs321 abs 1234567890123456 -> 1234567890123456 79 | ddabs322 abs 12345678000 -> 12345678000 80 | ddabs323 abs 1234567800 -> 1234567800 81 | ddabs324 abs 1234567890 -> 1234567890 82 | ddabs325 abs 1234567891 -> 1234567891 83 | ddabs326 abs 12345678901 -> 12345678901 84 | ddabs327 abs 1234567896 -> 1234567896 85 | 86 | -- zeros 87 | ddabs111 abs 0 -> 0 88 | ddabs112 abs -0 -> 0 89 | ddabs113 abs 0E+6 -> 0E+6 90 | ddabs114 abs -0E+6 -> 0E+6 91 | ddabs115 abs 0.0000 -> 0.0000 92 | ddabs116 abs -0.0000 -> 0.0000 93 | ddabs117 abs 0E-141 -> 0E-141 94 | ddabs118 abs -0E-141 -> 0E-141 95 | 96 | -- full coefficients, alternating bits 97 | ddabs121 abs 2682682682682682 -> 2682682682682682 98 | ddabs122 abs -2682682682682682 -> 2682682682682682 99 | ddabs123 abs 1341341341341341 -> 1341341341341341 100 | ddabs124 abs -1341341341341341 -> 1341341341341341 101 | 102 | -- Nmax, Nmin, Ntiny 103 | ddabs131 abs 9.999999999999999E+384 -> 9.999999999999999E+384 104 | ddabs132 abs 1E-383 -> 1E-383 105 | ddabs133 abs 1.000000000000000E-383 -> 1.000000000000000E-383 106 | ddabs134 abs 1E-398 -> 1E-398 Subnormal 107 | 108 | ddabs135 abs -1E-398 -> 1E-398 Subnormal 109 | ddabs136 abs -1.000000000000000E-383 -> 1.000000000000000E-383 110 | ddabs137 abs -1E-383 -> 1E-383 111 | ddabs138 abs -9.999999999999999E+384 -> 9.999999999999999E+384 112 | 113 | -- specials 114 | ddabs520 abs 'Inf' -> 'Infinity' 115 | ddabs521 abs '-Inf' -> 'Infinity' 116 | ddabs522 abs NaN -> NaN 117 | ddabs523 abs sNaN -> NaN Invalid_operation 118 | ddabs524 abs NaN22 -> NaN22 119 | ddabs525 abs sNaN33 -> NaN33 Invalid_operation 120 | ddabs526 abs -NaN22 -> -NaN22 121 | ddabs527 abs -sNaN33 -> -NaN33 Invalid_operation 122 | 123 | -- Null tests 124 | ddabs900 abs # -> NaN Invalid_operation 125 | 126 | -------------------------------------------------------------------------------- /testdata/dqAbs.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- dqAbs.decTest -- decQuad absolute value, heeding sNaN -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | extended: 1 22 | clamp: 1 23 | precision: 34 24 | maxExponent: 6144 25 | minExponent: -6143 26 | rounding: half_even 27 | 28 | dqabs001 abs '1' -> '1' 29 | dqabs002 abs '-1' -> '1' 30 | dqabs003 abs '1.00' -> '1.00' 31 | dqabs004 abs '-1.00' -> '1.00' 32 | dqabs005 abs '0' -> '0' 33 | dqabs006 abs '0.00' -> '0.00' 34 | dqabs007 abs '00.0' -> '0.0' 35 | dqabs008 abs '00.00' -> '0.00' 36 | dqabs009 abs '00' -> '0' 37 | 38 | dqabs010 abs '-2' -> '2' 39 | dqabs011 abs '2' -> '2' 40 | dqabs012 abs '-2.00' -> '2.00' 41 | dqabs013 abs '2.00' -> '2.00' 42 | dqabs014 abs '-0' -> '0' 43 | dqabs015 abs '-0.00' -> '0.00' 44 | dqabs016 abs '-00.0' -> '0.0' 45 | dqabs017 abs '-00.00' -> '0.00' 46 | dqabs018 abs '-00' -> '0' 47 | 48 | dqabs020 abs '-2000000' -> '2000000' 49 | dqabs021 abs '2000000' -> '2000000' 50 | 51 | dqabs030 abs '+0.1' -> '0.1' 52 | dqabs031 abs '-0.1' -> '0.1' 53 | dqabs032 abs '+0.01' -> '0.01' 54 | dqabs033 abs '-0.01' -> '0.01' 55 | dqabs034 abs '+0.001' -> '0.001' 56 | dqabs035 abs '-0.001' -> '0.001' 57 | dqabs036 abs '+0.000001' -> '0.000001' 58 | dqabs037 abs '-0.000001' -> '0.000001' 59 | dqabs038 abs '+0.000000000001' -> '1E-12' 60 | dqabs039 abs '-0.000000000001' -> '1E-12' 61 | 62 | -- examples from decArith 63 | dqabs040 abs '2.1' -> '2.1' 64 | dqabs041 abs '-100' -> '100' 65 | dqabs042 abs '101.5' -> '101.5' 66 | dqabs043 abs '-101.5' -> '101.5' 67 | 68 | -- more fixed, potential LHS swaps/overlays if done by subtract 0 69 | dqabs060 abs '-56267E-10' -> '0.0000056267' 70 | dqabs061 abs '-56267E-5' -> '0.56267' 71 | dqabs062 abs '-56267E-2' -> '562.67' 72 | dqabs063 abs '-56267E-1' -> '5626.7' 73 | dqabs065 abs '-56267E-0' -> '56267' 74 | 75 | -- subnormals and underflow 76 | 77 | -- long operand tests 78 | dqabs321 abs 1234567890123456 -> 1234567890123456 79 | dqabs322 abs 12345678000 -> 12345678000 80 | dqabs323 abs 1234567800 -> 1234567800 81 | dqabs324 abs 1234567890 -> 1234567890 82 | dqabs325 abs 1234567891 -> 1234567891 83 | dqabs326 abs 12345678901 -> 12345678901 84 | dqabs327 abs 1234567896 -> 1234567896 85 | 86 | -- zeros 87 | dqabs111 abs 0 -> 0 88 | dqabs112 abs -0 -> 0 89 | dqabs113 abs 0E+6 -> 0E+6 90 | dqabs114 abs -0E+6 -> 0E+6 91 | dqabs115 abs 0.0000 -> 0.0000 92 | dqabs116 abs -0.0000 -> 0.0000 93 | dqabs117 abs 0E-141 -> 0E-141 94 | dqabs118 abs -0E-141 -> 0E-141 95 | 96 | -- full coefficients, alternating bits 97 | dqabs121 abs 2682682682682682682682682682682682 -> 2682682682682682682682682682682682 98 | dqabs122 abs -2682682682682682682682682682682682 -> 2682682682682682682682682682682682 99 | dqabs123 abs 1341341341341341341341341341341341 -> 1341341341341341341341341341341341 100 | dqabs124 abs -1341341341341341341341341341341341 -> 1341341341341341341341341341341341 101 | 102 | -- Nmax, Nmin, Ntiny 103 | dqabs131 abs 9.999999999999999999999999999999999E+6144 -> 9.999999999999999999999999999999999E+6144 104 | dqabs132 abs 1E-6143 -> 1E-6143 105 | dqabs133 abs 1.000000000000000000000000000000000E-6143 -> 1.000000000000000000000000000000000E-6143 106 | dqabs134 abs 1E-6176 -> 1E-6176 Subnormal 107 | 108 | dqabs135 abs -1E-6176 -> 1E-6176 Subnormal 109 | dqabs136 abs -1.000000000000000000000000000000000E-6143 -> 1.000000000000000000000000000000000E-6143 110 | dqabs137 abs -1E-6143 -> 1E-6143 111 | dqabs138 abs -9.999999999999999999999999999999999E+6144 -> 9.999999999999999999999999999999999E+6144 112 | 113 | -- specials 114 | dqabs520 abs 'Inf' -> 'Infinity' 115 | dqabs521 abs '-Inf' -> 'Infinity' 116 | dqabs522 abs NaN -> NaN 117 | dqabs523 abs sNaN -> NaN Invalid_operation 118 | dqabs524 abs NaN22 -> NaN22 119 | dqabs525 abs sNaN33 -> NaN33 Invalid_operation 120 | dqabs526 abs -NaN22 -> -NaN22 121 | dqabs527 abs -sNaN33 -> -NaN33 Invalid_operation 122 | 123 | -- Null tests 124 | dqabs900 abs # -> NaN Invalid_operation 125 | 126 | -------------------------------------------------------------------------------- /testdata/trim.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- trim.decTest -- remove insignificant trailing zeros -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | extended: 1 22 | precision: 9 23 | rounding: half_up 24 | maxExponent: 999 25 | minexponent: -999 26 | 27 | trmx001 trim '1' -> '1' 28 | trmx002 trim '-1' -> '-1' 29 | trmx003 trim '1.00' -> '1' 30 | trmx004 trim '-1.00' -> '-1' 31 | trmx005 trim '0' -> '0' 32 | trmx006 trim '0.00' -> '0' 33 | trmx007 trim '00.0' -> '0' 34 | trmx008 trim '00.00' -> '0' 35 | trmx009 trim '00' -> '0' 36 | 37 | trmx010 trim '-2' -> '-2' 38 | trmx011 trim '2' -> '2' 39 | trmx012 trim '-2.00' -> '-2' 40 | trmx013 trim '2.00' -> '2' 41 | trmx014 trim '-0' -> '-0' 42 | trmx015 trim '-0.00' -> '-0' 43 | trmx016 trim '-00.0' -> '-0' 44 | trmx017 trim '-00.00' -> '-0' 45 | trmx018 trim '-00' -> '-0' 46 | trmx019 trim '0E+5' -> '0' 47 | trmx020 trim '-0E+1' -> '-0' 48 | 49 | trmx030 trim '+0.1' -> '0.1' 50 | trmx031 trim '-0.1' -> '-0.1' 51 | trmx032 trim '+0.01' -> '0.01' 52 | trmx033 trim '-0.01' -> '-0.01' 53 | trmx034 trim '+0.001' -> '0.001' 54 | trmx035 trim '-0.001' -> '-0.001' 55 | trmx036 trim '+0.000001' -> '0.000001' 56 | trmx037 trim '-0.000001' -> '-0.000001' 57 | trmx038 trim '+0.000000000001' -> '1E-12' 58 | trmx039 trim '-0.000000000001' -> '-1E-12' 59 | 60 | trmx041 trim 1.1 -> 1.1 61 | trmx042 trim 1.10 -> 1.1 62 | trmx043 trim 1.100 -> 1.1 63 | trmx044 trim 1.110 -> 1.11 64 | trmx045 trim -1.1 -> -1.1 65 | trmx046 trim -1.10 -> -1.1 66 | trmx047 trim -1.100 -> -1.1 67 | trmx048 trim -1.110 -> -1.11 68 | trmx049 trim 9.9 -> 9.9 69 | trmx050 trim 9.90 -> 9.9 70 | trmx051 trim 9.900 -> 9.9 71 | trmx052 trim 9.990 -> 9.99 72 | trmx053 trim -9.9 -> -9.9 73 | trmx054 trim -9.90 -> -9.9 74 | trmx055 trim -9.900 -> -9.9 75 | trmx056 trim -9.990 -> -9.99 76 | 77 | -- some insignificant trailing fractional zeros 78 | trmx060 trim 10.0 -> 10 79 | trmx061 trim 10.00 -> 10 80 | trmx062 trim 100.0 -> 100 81 | trmx063 trim 100.00 -> 100 82 | trmx064 trim 1.1000E+3 -> 1100 83 | trmx065 trim 1.10000E+3 -> 1100 84 | trmx066 trim -10.0 -> -10 85 | trmx067 trim -10.00 -> -10 86 | trmx068 trim -100.0 -> -100 87 | trmx069 trim -100.00 -> -100 88 | trmx070 trim -1.1000E+3 -> -1100 89 | trmx071 trim -1.10000E+3 -> -1100 90 | 91 | -- some insignificant trailing zeros with positive exponent 92 | trmx080 trim 10E+1 -> 1E+2 93 | trmx081 trim 100E+1 -> 1E+3 94 | trmx082 trim 1.0E+2 -> 1E+2 95 | trmx083 trim 1.0E+3 -> 1E+3 96 | trmx084 trim 1.1E+3 -> 1.1E+3 97 | trmx085 trim 1.00E+3 -> 1E+3 98 | trmx086 trim 1.10E+3 -> 1.1E+3 99 | trmx087 trim -10E+1 -> -1E+2 100 | trmx088 trim -100E+1 -> -1E+3 101 | trmx089 trim -1.0E+2 -> -1E+2 102 | trmx090 trim -1.0E+3 -> -1E+3 103 | trmx091 trim -1.1E+3 -> -1.1E+3 104 | trmx092 trim -1.00E+3 -> -1E+3 105 | trmx093 trim -1.10E+3 -> -1.1E+3 106 | 107 | -- some significant trailing zeros 108 | trmx100 trim 11 -> 11 109 | trmx101 trim 10 -> 10 110 | trmx102 trim 10. -> 10 111 | trmx103 trim 1.1E+1 -> 11 112 | trmx104 trim 1.0E+1 -> 10 113 | trmx105 trim 1.10E+2 -> 110 114 | trmx106 trim 1.00E+2 -> 100 115 | trmx107 trim 1.100E+3 -> 1100 116 | trmx108 trim 1.000E+3 -> 1000 117 | trmx109 trim 1.000000E+6 -> 1000000 118 | trmx110 trim -11 -> -11 119 | trmx111 trim -10 -> -10 120 | trmx112 trim -10. -> -10 121 | trmx113 trim -1.1E+1 -> -11 122 | trmx114 trim -1.0E+1 -> -10 123 | trmx115 trim -1.10E+2 -> -110 124 | trmx116 trim -1.00E+2 -> -100 125 | trmx117 trim -1.100E+3 -> -1100 126 | trmx118 trim -1.000E+3 -> -1000 127 | trmx119 trim -1.00000E+5 -> -100000 128 | trmx120 trim -1.000000E+6 -> -1000000 129 | 130 | -- examples from decArith 131 | trmx140 trim '2.1' -> '2.1' 132 | trmx141 trim '-2.0' -> '-2' 133 | trmx142 trim '1.200' -> '1.2' 134 | trmx143 trim '-120' -> '-120' 135 | trmx144 trim '120.00' -> '120' 136 | trmx145 trim '0.00' -> '0' 137 | 138 | -- utilities pass through specials without raising exceptions 139 | trmx320 trim 'Inf' -> 'Infinity' 140 | trmx321 trim '-Inf' -> '-Infinity' 141 | trmx322 trim NaN -> NaN 142 | trmx323 trim sNaN -> sNaN 143 | trmx324 trim NaN999 -> NaN999 144 | trmx325 trim sNaN777 -> sNaN777 145 | trmx326 trim -NaN -> -NaN 146 | trmx327 trim -sNaN -> -sNaN 147 | trmx328 trim -NaN999 -> -NaN999 148 | trmx329 trim -sNaN777 -> -sNaN777 149 | 150 | -- Null test 151 | trmx900 trim # -> NaN Invalid_operation 152 | -------------------------------------------------------------------------------- /dec/src/conv.rs: -------------------------------------------------------------------------------- 1 | // Copyright Materialize, Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License in the LICENSE file at the 6 | // root of this repository, or online at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | /// Converts from some arbitrary signed integer `$n` whose size is a multiple of 17 | /// 32 into a decimal of type `$t`. 18 | /// 19 | /// `$cx` is a `Context::<$t>` used to generate a value of `$t`. It must outlive 20 | /// the macro call to, e.g., allow checking the context's status. 21 | macro_rules! from_signed_int { 22 | ($t:ty, $cx:expr, $n:expr) => { 23 | __from_int!($t, i32, $cx, $n) 24 | }; 25 | } 26 | 27 | /// Like `from_signed_int!` but for unsigned integers. 28 | macro_rules! from_unsigned_int { 29 | ($t:ty, $cx:expr, $n:expr) => { 30 | __from_int!($t, u32, $cx, $n) 31 | }; 32 | } 33 | 34 | macro_rules! __from_int { 35 | ($t:ty, $l:ty, $cx:expr, $n:expr) => {{ 36 | let n = $n.to_be_bytes(); 37 | assert!( 38 | n.len() % 4 == 0 && n.len() >= 4, 39 | "from_int requires size of integer to be a multiple of 32" 40 | ); 41 | 42 | // Process `$n` in 32-bit chunks. Only the first chunk has to be sign 43 | // aware. Each turn of the loop computes `d = d * 2^32 + n`, where `n` 44 | // is the next 32-bit chunk. 45 | let mut d = <$t>::from(<$l>::from_be_bytes(n[..4].try_into().unwrap())); 46 | for i in (4..n.len()).step_by(4) { 47 | d = $cx.mul(d, <$t>::TWO_POW_32); 48 | let n = <$t>::from(u32::from_be_bytes(n[i..i + 4].try_into().unwrap())); 49 | d = $cx.add(d, n); 50 | } 51 | 52 | d 53 | }}; 54 | } 55 | 56 | macro_rules! decimal_from_signed_int { 57 | ($cx:expr, $n:expr) => { 58 | __decimal_from_int!(i32, $cx, $n) 59 | }; 60 | } 61 | 62 | macro_rules! decimal_from_unsigned_int { 63 | ($cx:expr, $n:expr) => { 64 | __decimal_from_int!(u32, $cx, $n) 65 | }; 66 | } 67 | 68 | // Equivalent to `__from_int`, but with `Decimal`'s API. 69 | macro_rules! __decimal_from_int { 70 | ($l:ty, $cx:expr, $n:expr) => {{ 71 | let n = $n.to_be_bytes(); 72 | assert!( 73 | n.len() % 4 == 0 && n.len() >= 4, 74 | "from_int requires size of integer to be a multiple of 32" 75 | ); 76 | let two_pow_32 = Decimal::::two_pow_32(); 77 | 78 | let mut d = Decimal::::from(<$l>::from_be_bytes(n[..4].try_into().unwrap())); 79 | for i in (4..n.len()).step_by(4) { 80 | $cx.mul(&mut d, &two_pow_32); 81 | let n = Decimal::::from(u32::from_be_bytes(n[i..i + 4].try_into().unwrap())); 82 | $cx.add(&mut d, &n); 83 | } 84 | 85 | d 86 | }}; 87 | } 88 | 89 | /// Looks up character representation of a densely packed digit. 90 | macro_rules! dpd2char { 91 | ($dpd:expr, $digits:expr, $digits_idx:expr) => {{ 92 | let mut u = [0u8; 4]; 93 | let bin_idx = (unsafe { decnumber_sys::DPD2BIN[$dpd] } as usize) << 2; 94 | u.copy_from_slice(unsafe { &decnumber_sys::BIN2CHAR[bin_idx..bin_idx + 4] }); 95 | if $digits_idx > 0 { 96 | $digits[$digits_idx..$digits_idx + 3].copy_from_slice(&u[1..4]); 97 | $digits_idx += 3; 98 | } else if u[0] > 0 { 99 | // skip leading zeroes; left align first value 100 | let d = (4 - u[0]) as usize; 101 | $digits[$digits_idx..$digits_idx + u[0] as usize].copy_from_slice(&u[d..4]); 102 | $digits_idx += u[0] as usize; 103 | } 104 | }}; 105 | } 106 | 107 | /// Produces a string-ified version of a `Vec` derived from a decimal. 108 | macro_rules! stringify_digits { 109 | ($s:expr, $digits:expr, $digits_idx:expr) => {{ 110 | if $digits_idx == 0 { 111 | $digits[0] = b'0'; 112 | $digits_idx = 1; 113 | } 114 | 115 | let e = $s.exponent(); 116 | if e >= 0 { 117 | let mut s = String::with_capacity($digits_idx + e as usize + 1); 118 | if $s.is_negative() { 119 | s.push('-'); 120 | } 121 | s.push_str(unsafe { std::str::from_utf8_unchecked(&$digits[..$digits_idx]) }); 122 | if $digits[0] != b'0' { 123 | for _ in 0..e { 124 | s.push('0'); 125 | } 126 | } 127 | s 128 | } else if $digits_idx as i32 > -e { 129 | let mut s = String::with_capacity($digits_idx + 2); 130 | if $s.is_negative() { 131 | s.push('-'); 132 | } 133 | let e = ($digits_idx as i32 + e) as usize; 134 | for d in &$digits[..e] { 135 | s.push(char::from(*d)); 136 | } 137 | s.push('.'); 138 | for d in &$digits[e..$digits_idx] { 139 | s.push(char::from(*d)); 140 | } 141 | s 142 | } else { 143 | let d = usize::try_from(-e).unwrap() - $digits_idx; 144 | let mut s = String::with_capacity($digits_idx + d + 3); 145 | if $s.is_negative() { 146 | s.push('-'); 147 | } 148 | // All digits after the decimal point. 149 | s.push_str("0."); 150 | for _ in 0..d { 151 | s.push('0'); 152 | } 153 | for d in &$digits[..$digits_idx] { 154 | s.push(char::from(*d)); 155 | } 156 | s 157 | } 158 | }}; 159 | } 160 | -------------------------------------------------------------------------------- /dectest/src/backend.rs: -------------------------------------------------------------------------------- 1 | // Copyright Materialize, Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License in the LICENSE file at the 6 | // root of this repository, or online at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | use std::cmp::Ordering; 17 | use std::error::Error; 18 | use std::fmt; 19 | 20 | use dec::{Class, Decimal128, Decimal32, Decimal64, Rounding, Status}; 21 | 22 | mod decimal; 23 | mod decimal128; 24 | mod decimal32; 25 | mod decimal64; 26 | 27 | pub use decimal::DecimalBackend; 28 | pub use decimal128::Decimal128Backend; 29 | pub use decimal32::Decimal32Backend; 30 | pub use decimal64::Decimal64Backend; 31 | 32 | pub enum BackendError { 33 | Unsupported, 34 | Failure { cause: Box }, 35 | } 36 | 37 | impl BackendError { 38 | pub fn failure(message: S) -> BackendError 39 | where 40 | S: Into, 41 | { 42 | let message = message.into(); 43 | BackendError::Failure { 44 | cause: message.into(), 45 | } 46 | } 47 | } 48 | 49 | impl From for BackendError 50 | where 51 | E: Error + 'static, 52 | { 53 | fn from(cause: E) -> BackendError { 54 | BackendError::Failure { 55 | cause: cause.into(), 56 | } 57 | } 58 | } 59 | 60 | pub type BackendResult = Result; 61 | 62 | pub trait Backend { 63 | type D: fmt::Display + Clone; 64 | 65 | const REPORTS_STATUS_CLAMPED: bool; 66 | const REPORTS_STATUS_ROUNDED: bool; 67 | const REPORTS_STATUS_SUBNORMAL: bool; 68 | 69 | fn new() -> Self; 70 | 71 | fn nan() -> Self::D; 72 | fn parse(&mut self, s: &str, precise: bool) -> Self::D; 73 | fn from_decimal32(&mut self, n: Decimal32) -> Self::D; 74 | fn from_decimal64(&mut self, n: Decimal64) -> Self::D; 75 | fn from_decimal128(&mut self, n: Decimal128) -> Self::D; 76 | fn to_decimal32(&mut self, n: &Self::D) -> Decimal32; 77 | fn to_decimal64(&mut self, n: &Self::D) -> Decimal64; 78 | fn to_decimal128(&mut self, n: &Self::D) -> Decimal128; 79 | 80 | fn status(&self) -> Status; 81 | fn clear_status(&mut self); 82 | fn set_clamp(&mut self, clamp: bool) -> BackendResult<()>; 83 | fn set_extended(&mut self, extended: bool) -> BackendResult<()>; 84 | fn set_max_exponent(&mut self, e: isize) -> BackendResult<()>; 85 | fn set_min_exponent(&mut self, e: isize) -> BackendResult<()>; 86 | fn set_precision(&mut self, p: usize) -> BackendResult<()>; 87 | fn set_rounding(&mut self, rounding: Rounding) -> BackendResult<()>; 88 | fn is_valid(&self, id: &str) -> bool; 89 | 90 | fn abs(&mut self, n: Self::D) -> BackendResult; 91 | fn add(&mut self, lhs: Self::D, rhs: Self::D) -> BackendResult; 92 | fn and(&mut self, lhs: Self::D, rhs: Self::D) -> BackendResult; 93 | fn canonical(&mut self, n: Self::D) -> BackendResult; 94 | fn class(&mut self, n: Self::D) -> Result; 95 | fn div(&mut self, lhs: Self::D, rhs: Self::D) -> BackendResult; 96 | fn div_integer(&mut self, lhs: Self::D, rhs: Self::D) -> BackendResult; 97 | fn exp(&mut self, n: Self::D) -> BackendResult; 98 | fn fma(&mut self, x: Self::D, y: Self::D, z: Self::D) -> BackendResult; 99 | fn ln(&mut self, n: Self::D) -> BackendResult; 100 | fn log10(&mut self, n: Self::D) -> BackendResult; 101 | fn logb(&mut self, n: Self::D) -> BackendResult; 102 | fn max(&mut self, lhs: Self::D, rhs: Self::D) -> BackendResult; 103 | fn max_abs(&mut self, lhs: Self::D, rhs: Self::D) -> BackendResult; 104 | fn min(&mut self, lhs: Self::D, rhs: Self::D) -> BackendResult; 105 | fn min_abs(&mut self, lhs: Self::D, rhs: Self::D) -> BackendResult; 106 | fn minus(&mut self, n: Self::D) -> BackendResult; 107 | fn mul(&mut self, lhs: Self::D, rhs: Self::D) -> BackendResult; 108 | fn next_minus(&mut self, n: Self::D) -> BackendResult; 109 | fn next_plus(&mut self, n: Self::D) -> BackendResult; 110 | fn next_toward(&mut self, lhs: Self::D, rhs: Self::D) -> BackendResult; 111 | fn invert(&mut self, n: Self::D) -> BackendResult; 112 | fn or(&mut self, lhs: Self::D, rhs: Self::D) -> BackendResult; 113 | fn partial_cmp(&mut self, lhs: Self::D, rhs: Self::D) -> BackendResult>; 114 | fn plus(&mut self, n: Self::D) -> BackendResult; 115 | fn pow(&mut self, x: Self::D, y: Self::D) -> BackendResult; 116 | fn quantize(&mut self, lhs: Self::D, rhs: Self::D) -> BackendResult; 117 | fn quantum_matches(&mut self, lhs: Self::D, rhs: Self::D) -> BackendResult; 118 | fn reduce(&mut self, n: Self::D) -> BackendResult; 119 | fn rem(&mut self, lhs: Self::D, rhs: Self::D) -> BackendResult; 120 | fn rem_near(&mut self, lhs: Self::D, rhs: Self::D) -> BackendResult; 121 | fn rotate(&mut self, lhs: Self::D, rhs: Self::D) -> BackendResult; 122 | fn round(&mut self, n: Self::D) -> BackendResult; 123 | fn scaleb(&mut self, x: Self::D, y: Self::D) -> BackendResult; 124 | fn shift(&mut self, lhs: Self::D, rhs: Self::D) -> BackendResult; 125 | fn sqrt(&mut self, n: Self::D) -> BackendResult; 126 | fn sub(&mut self, lhs: Self::D, rhs: Self::D) -> BackendResult; 127 | fn total_cmp(&mut self, lhs: Self::D, rhs: Self::D) -> BackendResult; 128 | fn xor(&mut self, lhs: Self::D, rhs: Self::D) -> BackendResult; 129 | } 130 | -------------------------------------------------------------------------------- /testdata/class.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- class.decTest -- Class operations -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | -- [New 2006.11.27] 22 | 23 | precision: 9 24 | maxExponent: 999 25 | minExponent: -999 26 | extended: 1 27 | clamp: 1 28 | rounding: half_even 29 | 30 | clasx001 class 0 -> +Zero 31 | clasx002 class 0.00 -> +Zero 32 | clasx003 class 0E+5 -> +Zero 33 | clasx004 class 1E-1007 -> +Subnormal 34 | clasx005 class 0.1E-999 -> +Subnormal 35 | clasx006 class 0.99999999E-999 -> +Subnormal 36 | clasx007 class 1.00000000E-999 -> +Normal 37 | clasx008 class 1E-999 -> +Normal 38 | clasx009 class 1E-100 -> +Normal 39 | clasx010 class 1E-10 -> +Normal 40 | clasx012 class 1E-1 -> +Normal 41 | clasx013 class 1 -> +Normal 42 | clasx014 class 2.50 -> +Normal 43 | clasx015 class 100.100 -> +Normal 44 | clasx016 class 1E+30 -> +Normal 45 | clasx017 class 1E+999 -> +Normal 46 | clasx018 class 9.99999999E+999 -> +Normal 47 | clasx019 class Inf -> +Infinity 48 | 49 | clasx021 class -0 -> -Zero 50 | clasx022 class -0.00 -> -Zero 51 | clasx023 class -0E+5 -> -Zero 52 | clasx024 class -1E-1007 -> -Subnormal 53 | clasx025 class -0.1E-999 -> -Subnormal 54 | clasx026 class -0.99999999E-999 -> -Subnormal 55 | clasx027 class -1.00000000E-999 -> -Normal 56 | clasx028 class -1E-999 -> -Normal 57 | clasx029 class -1E-100 -> -Normal 58 | clasx030 class -1E-10 -> -Normal 59 | clasx032 class -1E-1 -> -Normal 60 | clasx033 class -1 -> -Normal 61 | clasx034 class -2.50 -> -Normal 62 | clasx035 class -100.100 -> -Normal 63 | clasx036 class -1E+30 -> -Normal 64 | clasx037 class -1E+999 -> -Normal 65 | clasx038 class -9.99999999E+999 -> -Normal 66 | clasx039 class -Inf -> -Infinity 67 | 68 | clasx041 class NaN -> NaN 69 | clasx042 class -NaN -> NaN 70 | clasx043 class +NaN12345 -> NaN 71 | clasx044 class sNaN -> sNaN 72 | clasx045 class -sNaN -> sNaN 73 | clasx046 class +sNaN12345 -> sNaN 74 | 75 | 76 | -- decimal64 bounds 77 | 78 | precision: 16 79 | maxExponent: 384 80 | minExponent: -383 81 | clamp: 1 82 | rounding: half_even 83 | 84 | clasx201 class 0 -> +Zero 85 | clasx202 class 0.00 -> +Zero 86 | clasx203 class 0E+5 -> +Zero 87 | clasx204 class 1E-396 -> +Subnormal 88 | clasx205 class 0.1E-383 -> +Subnormal 89 | clasx206 class 0.999999999999999E-383 -> +Subnormal 90 | clasx207 class 1.000000000000000E-383 -> +Normal 91 | clasx208 class 1E-383 -> +Normal 92 | clasx209 class 1E-100 -> +Normal 93 | clasx210 class 1E-10 -> +Normal 94 | clasx212 class 1E-1 -> +Normal 95 | clasx213 class 1 -> +Normal 96 | clasx214 class 2.50 -> +Normal 97 | clasx215 class 100.100 -> +Normal 98 | clasx216 class 1E+30 -> +Normal 99 | clasx217 class 1E+384 -> +Normal 100 | clasx218 class 9.999999999999999E+384 -> +Normal 101 | clasx219 class Inf -> +Infinity 102 | 103 | clasx221 class -0 -> -Zero 104 | clasx222 class -0.00 -> -Zero 105 | clasx223 class -0E+5 -> -Zero 106 | clasx224 class -1E-396 -> -Subnormal 107 | clasx225 class -0.1E-383 -> -Subnormal 108 | clasx226 class -0.999999999999999E-383 -> -Subnormal 109 | clasx227 class -1.000000000000000E-383 -> -Normal 110 | clasx228 class -1E-383 -> -Normal 111 | clasx229 class -1E-100 -> -Normal 112 | clasx230 class -1E-10 -> -Normal 113 | clasx232 class -1E-1 -> -Normal 114 | clasx233 class -1 -> -Normal 115 | clasx234 class -2.50 -> -Normal 116 | clasx235 class -100.100 -> -Normal 117 | clasx236 class -1E+30 -> -Normal 118 | clasx237 class -1E+384 -> -Normal 119 | clasx238 class -9.999999999999999E+384 -> -Normal 120 | clasx239 class -Inf -> -Infinity 121 | 122 | clasx241 class NaN -> NaN 123 | clasx242 class -NaN -> NaN 124 | clasx243 class +NaN12345 -> NaN 125 | clasx244 class sNaN -> sNaN 126 | clasx245 class -sNaN -> sNaN 127 | clasx246 class +sNaN12345 -> sNaN 128 | 129 | 130 | 131 | -------------------------------------------------------------------------------- /testdata/ddLogB.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- ddLogB.decTest -- integral 754r adjusted exponent, for decDoubles -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | precision: 16 22 | maxExponent: 384 23 | minExponent: -383 24 | extended: 1 25 | clamp: 1 26 | rounding: half_even 27 | 28 | -- basics 29 | ddlogb000 logb 0 -> -Infinity Division_by_zero 30 | ddlogb001 logb 1E-398 -> -398 31 | ddlogb002 logb 1E-383 -> -383 32 | ddlogb003 logb 0.001 -> -3 33 | ddlogb004 logb 0.03 -> -2 34 | ddlogb005 logb 1 -> 0 35 | ddlogb006 logb 2 -> 0 36 | ddlogb007 logb 2.5 -> 0 37 | ddlogb008 logb 2.500 -> 0 38 | ddlogb009 logb 10 -> 1 39 | ddlogb010 logb 70 -> 1 40 | ddlogb011 logb 100 -> 2 41 | ddlogb012 logb 333 -> 2 42 | ddlogb013 logb 9E+384 -> 384 43 | ddlogb014 logb +Infinity -> Infinity 44 | 45 | -- negatives appear to be treated as positives 46 | ddlogb021 logb -0 -> -Infinity Division_by_zero 47 | ddlogb022 logb -1E-398 -> -398 48 | ddlogb023 logb -9E-383 -> -383 49 | ddlogb024 logb -0.001 -> -3 50 | ddlogb025 logb -1 -> 0 51 | ddlogb026 logb -2 -> 0 52 | ddlogb027 logb -10 -> 1 53 | ddlogb028 logb -70 -> 1 54 | ddlogb029 logb -100 -> 2 55 | ddlogb030 logb -9E+384 -> 384 56 | ddlogb031 logb -Infinity -> Infinity 57 | 58 | -- zeros 59 | ddlogb111 logb 0 -> -Infinity Division_by_zero 60 | ddlogb112 logb -0 -> -Infinity Division_by_zero 61 | ddlogb113 logb 0E+4 -> -Infinity Division_by_zero 62 | ddlogb114 logb -0E+4 -> -Infinity Division_by_zero 63 | ddlogb115 logb 0.0000 -> -Infinity Division_by_zero 64 | ddlogb116 logb -0.0000 -> -Infinity Division_by_zero 65 | ddlogb117 logb 0E-141 -> -Infinity Division_by_zero 66 | ddlogb118 logb -0E-141 -> -Infinity Division_by_zero 67 | 68 | -- full coefficients, alternating bits 69 | ddlogb121 logb 268268268 -> 8 70 | ddlogb122 logb -268268268 -> 8 71 | ddlogb123 logb 134134134 -> 8 72 | ddlogb124 logb -134134134 -> 8 73 | 74 | -- Nmax, Nmin, Ntiny 75 | ddlogb131 logb 9.999999999999999E+384 -> 384 76 | ddlogb132 logb 1E-383 -> -383 77 | ddlogb133 logb 1.000000000000000E-383 -> -383 78 | ddlogb134 logb 1E-398 -> -398 79 | 80 | ddlogb135 logb -1E-398 -> -398 81 | ddlogb136 logb -1.000000000000000E-383 -> -383 82 | ddlogb137 logb -1E-383 -> -383 83 | ddlogb138 logb -9.999999999999999E+384 -> 384 84 | 85 | -- ones 86 | ddlogb0061 logb 1 -> 0 87 | ddlogb0062 logb 1.0 -> 0 88 | ddlogb0063 logb 1.000000000000000 -> 0 89 | 90 | -- notable cases -- exact powers of 10 91 | ddlogb1100 logb 1 -> 0 92 | ddlogb1101 logb 10 -> 1 93 | ddlogb1102 logb 100 -> 2 94 | ddlogb1103 logb 1000 -> 3 95 | ddlogb1104 logb 10000 -> 4 96 | ddlogb1105 logb 100000 -> 5 97 | ddlogb1106 logb 1000000 -> 6 98 | ddlogb1107 logb 10000000 -> 7 99 | ddlogb1108 logb 100000000 -> 8 100 | ddlogb1109 logb 1000000000 -> 9 101 | ddlogb1110 logb 10000000000 -> 10 102 | ddlogb1111 logb 100000000000 -> 11 103 | ddlogb1112 logb 1000000000000 -> 12 104 | ddlogb1113 logb 0.00000000001 -> -11 105 | ddlogb1114 logb 0.0000000001 -> -10 106 | ddlogb1115 logb 0.000000001 -> -9 107 | ddlogb1116 logb 0.00000001 -> -8 108 | ddlogb1117 logb 0.0000001 -> -7 109 | ddlogb1118 logb 0.000001 -> -6 110 | ddlogb1119 logb 0.00001 -> -5 111 | ddlogb1120 logb 0.0001 -> -4 112 | ddlogb1121 logb 0.001 -> -3 113 | ddlogb1122 logb 0.01 -> -2 114 | ddlogb1123 logb 0.1 -> -1 115 | ddlogb1124 logb 1E-99 -> -99 116 | ddlogb1125 logb 1E-100 -> -100 117 | ddlogb1127 logb 1E-299 -> -299 118 | ddlogb1126 logb 1E-383 -> -383 119 | 120 | -- suggestions from Ilan Nehama 121 | ddlogb1400 logb 10E-3 -> -2 122 | ddlogb1401 logb 10E-2 -> -1 123 | ddlogb1402 logb 100E-2 -> 0 124 | ddlogb1403 logb 1000E-2 -> 1 125 | ddlogb1404 logb 10000E-2 -> 2 126 | ddlogb1405 logb 10E-1 -> 0 127 | ddlogb1406 logb 100E-1 -> 1 128 | ddlogb1407 logb 1000E-1 -> 2 129 | ddlogb1408 logb 10000E-1 -> 3 130 | ddlogb1409 logb 10E0 -> 1 131 | ddlogb1410 logb 100E0 -> 2 132 | ddlogb1411 logb 1000E0 -> 3 133 | ddlogb1412 logb 10000E0 -> 4 134 | ddlogb1413 logb 10E1 -> 2 135 | ddlogb1414 logb 100E1 -> 3 136 | ddlogb1415 logb 1000E1 -> 4 137 | ddlogb1416 logb 10000E1 -> 5 138 | ddlogb1417 logb 10E2 -> 3 139 | ddlogb1418 logb 100E2 -> 4 140 | ddlogb1419 logb 1000E2 -> 5 141 | ddlogb1420 logb 10000E2 -> 6 142 | 143 | -- special values 144 | ddlogb820 logb Infinity -> Infinity 145 | ddlogb821 logb 0 -> -Infinity Division_by_zero 146 | ddlogb822 logb NaN -> NaN 147 | ddlogb823 logb sNaN -> NaN Invalid_operation 148 | -- propagating NaNs 149 | ddlogb824 logb sNaN123 -> NaN123 Invalid_operation 150 | ddlogb825 logb -sNaN321 -> -NaN321 Invalid_operation 151 | ddlogb826 logb NaN456 -> NaN456 152 | ddlogb827 logb -NaN654 -> -NaN654 153 | ddlogb828 logb NaN1 -> NaN1 154 | 155 | -- Null test 156 | ddlogb900 logb # -> NaN Invalid_operation 157 | 158 | 159 | -------------------------------------------------------------------------------- /testdata/dqLogB.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- dqLogB.decTest -- integral 754r adjusted exponent, for decQuads -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | extended: 1 22 | clamp: 1 23 | precision: 34 24 | maxExponent: 6144 25 | minExponent: -6143 26 | rounding: half_even 27 | 28 | -- basics 29 | dqlogb000 logb 0 -> -Infinity Division_by_zero 30 | dqlogb001 logb 1E-6176 -> -6176 31 | dqlogb002 logb 1E-6143 -> -6143 32 | dqlogb003 logb 0.001 -> -3 33 | dqlogb004 logb 0.03 -> -2 34 | dqlogb005 logb 1 -> 0 35 | dqlogb006 logb 2 -> 0 36 | dqlogb007 logb 2.5 -> 0 37 | dqlogb008 logb 2.50 -> 0 38 | dqlogb009 logb 2.500 -> 0 39 | dqlogb010 logb 10 -> 1 40 | dqlogb011 logb 70 -> 1 41 | dqlogb012 logb 100 -> 2 42 | dqlogb013 logb 250 -> 2 43 | dqlogb014 logb 9E+6144 -> 6144 44 | dqlogb015 logb +Infinity -> Infinity 45 | 46 | -- negatives appear to be treated as positives 47 | dqlogb021 logb -0 -> -Infinity Division_by_zero 48 | dqlogb022 logb -1E-6176 -> -6176 49 | dqlogb023 logb -9E-6143 -> -6143 50 | dqlogb024 logb -0.001 -> -3 51 | dqlogb025 logb -1 -> 0 52 | dqlogb026 logb -2 -> 0 53 | dqlogb027 logb -10 -> 1 54 | dqlogb028 logb -70 -> 1 55 | dqlogb029 logb -100 -> 2 56 | dqlogb030 logb -9E+6144 -> 6144 57 | dqlogb031 logb -Infinity -> Infinity 58 | 59 | -- zeros 60 | dqlogb111 logb 0 -> -Infinity Division_by_zero 61 | dqlogb112 logb -0 -> -Infinity Division_by_zero 62 | dqlogb113 logb 0E+4 -> -Infinity Division_by_zero 63 | dqlogb114 logb -0E+4 -> -Infinity Division_by_zero 64 | dqlogb115 logb 0.0000 -> -Infinity Division_by_zero 65 | dqlogb116 logb -0.0000 -> -Infinity Division_by_zero 66 | dqlogb117 logb 0E-141 -> -Infinity Division_by_zero 67 | dqlogb118 logb -0E-141 -> -Infinity Division_by_zero 68 | 69 | -- full coefficients, alternating bits 70 | dqlogb121 logb 268268268 -> 8 71 | dqlogb122 logb -268268268 -> 8 72 | dqlogb123 logb 134134134 -> 8 73 | dqlogb124 logb -134134134 -> 8 74 | 75 | -- Nmax, Nmin, Ntiny 76 | dqlogb131 logb 9.999999999999999999999999999999999E+6144 -> 6144 77 | dqlogb132 logb 1E-6143 -> -6143 78 | dqlogb133 logb 1.000000000000000000000000000000000E-6143 -> -6143 79 | dqlogb134 logb 1E-6176 -> -6176 80 | 81 | dqlogb135 logb -1E-6176 -> -6176 82 | dqlogb136 logb -1.000000000000000000000000000000000E-6143 -> -6143 83 | dqlogb137 logb -1E-6143 -> -6143 84 | dqlogb1614 logb -9.999999999999999999999999999999999E+6144 -> 6144 85 | 86 | -- ones 87 | dqlogb0061 logb 1 -> 0 88 | dqlogb0062 logb 1.0 -> 0 89 | dqlogb0063 logb 1.000000000000000 -> 0 90 | 91 | -- notable cases -- exact powers of 10 92 | dqlogb1100 logb 1 -> 0 93 | dqlogb1101 logb 10 -> 1 94 | dqlogb1102 logb 100 -> 2 95 | dqlogb1103 logb 1000 -> 3 96 | dqlogb1104 logb 10000 -> 4 97 | dqlogb1105 logb 100000 -> 5 98 | dqlogb1106 logb 1000000 -> 6 99 | dqlogb1107 logb 10000000 -> 7 100 | dqlogb1108 logb 100000000 -> 8 101 | dqlogb1109 logb 1000000000 -> 9 102 | dqlogb1110 logb 10000000000 -> 10 103 | dqlogb1111 logb 100000000000 -> 11 104 | dqlogb1112 logb 1000000000000 -> 12 105 | dqlogb1113 logb 0.00000000001 -> -11 106 | dqlogb1114 logb 0.0000000001 -> -10 107 | dqlogb1115 logb 0.000000001 -> -9 108 | dqlogb1116 logb 0.00000001 -> -8 109 | dqlogb1117 logb 0.0000001 -> -7 110 | dqlogb1118 logb 0.000001 -> -6 111 | dqlogb1119 logb 0.00001 -> -5 112 | dqlogb1120 logb 0.0001 -> -4 113 | dqlogb1121 logb 0.001 -> -3 114 | dqlogb1122 logb 0.01 -> -2 115 | dqlogb1123 logb 0.1 -> -1 116 | dqlogb1124 logb 1E-99 -> -99 117 | dqlogb1125 logb 1E-100 -> -100 118 | dqlogb1127 logb 1E-299 -> -299 119 | dqlogb1126 logb 1E-6143 -> -6143 120 | 121 | -- suggestions from Ilan Nehama 122 | dqlogb1400 logb 10E-3 -> -2 123 | dqlogb1401 logb 10E-2 -> -1 124 | dqlogb1402 logb 100E-2 -> 0 125 | dqlogb1403 logb 1000E-2 -> 1 126 | dqlogb1404 logb 10000E-2 -> 2 127 | dqlogb1405 logb 10E-1 -> 0 128 | dqlogb1406 logb 100E-1 -> 1 129 | dqlogb1407 logb 1000E-1 -> 2 130 | dqlogb1408 logb 10000E-1 -> 3 131 | dqlogb1409 logb 10E0 -> 1 132 | dqlogb1410 logb 100E0 -> 2 133 | dqlogb1411 logb 1000E0 -> 3 134 | dqlogb1412 logb 10000E0 -> 4 135 | dqlogb1413 logb 10E1 -> 2 136 | dqlogb1414 logb 100E1 -> 3 137 | dqlogb1415 logb 1000E1 -> 4 138 | dqlogb1416 logb 10000E1 -> 5 139 | dqlogb1417 logb 10E2 -> 3 140 | dqlogb1418 logb 100E2 -> 4 141 | dqlogb1419 logb 1000E2 -> 5 142 | dqlogb1420 logb 10000E2 -> 6 143 | 144 | -- special values 145 | dqlogb820 logb Infinity -> Infinity 146 | dqlogb821 logb 0 -> -Infinity Division_by_zero 147 | dqlogb822 logb NaN -> NaN 148 | dqlogb823 logb sNaN -> NaN Invalid_operation 149 | -- propagating NaNs 150 | dqlogb824 logb sNaN123 -> NaN123 Invalid_operation 151 | dqlogb825 logb -sNaN321 -> -NaN321 Invalid_operation 152 | dqlogb826 logb NaN456 -> NaN456 153 | dqlogb827 logb -NaN654 -> -NaN654 154 | dqlogb828 logb NaN1 -> NaN1 155 | 156 | -- Null test 157 | dqlogb900 logb # -> NaN Invalid_operation 158 | 159 | 160 | -------------------------------------------------------------------------------- /dec/benches/dec.rs: -------------------------------------------------------------------------------- 1 | // Copyright Materialize, Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License in the LICENSE file at the 6 | // root of this repository, or online at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | use std::convert::TryFrom; 17 | 18 | use criterion::{black_box, criterion_group, criterion_main, Bencher, Criterion}; 19 | use rand::{thread_rng, Rng}; 20 | 21 | use dec::{Context, Decimal, Decimal128, Decimal64}; 22 | 23 | fn bench_decode_decimal64(d: Decimal64, b: &mut Bencher) { 24 | b.iter_with_setup(|| d.clone(), |d| (d.exponent(), d.coefficient())) 25 | } 26 | 27 | fn bench_decode_decimal128(d: Decimal128, b: &mut Bencher) { 28 | b.iter_with_setup(|| d.clone(), |d| (d.exponent(), d.coefficient())) 29 | } 30 | 31 | pub fn bench_decode(c: &mut Criterion) { 32 | // decode_decimal64 33 | let mut rng = thread_rng(); 34 | let mut cx = Context::::default(); 35 | let d64 = cx.from_i64(rng.gen()); 36 | c.bench_function("decode_decimal64", |b| bench_decode_decimal64(d64, b)); 37 | 38 | // decode_decimal128 39 | let mut rng = thread_rng(); 40 | let mut cx = Context::::default(); 41 | let d128 = cx.from_i128(rng.gen()); 42 | c.bench_function("decode_decimal128", |b| bench_decode_decimal128(d128, b)); 43 | } 44 | 45 | pub fn bench_parse(c: &mut Criterion) { 46 | let mut cx = Context::>::default(); 47 | c.bench_function("parse_decimal", |b| { 48 | b.iter(|| { 49 | black_box(cx.from_f64(black_box(f64::MIN))); 50 | black_box(cx.from_f64(black_box(f64::from_bits(0x8008000000000000)))); 51 | black_box(cx.from_f64(black_box(f64::MAX))); 52 | }) 53 | }); 54 | } 55 | 56 | pub fn bench_to_string(d: Decimal128, b: &mut Bencher) { 57 | b.iter_with_setup( 58 | || { 59 | let mut cx = Context::::default(); 60 | [-50, 0, 50] 61 | .iter() 62 | .map(|exp| { 63 | let mut d = d.clone(); 64 | cx.set_exponent(&mut d, *exp); 65 | d 66 | }) 67 | .collect::>() 68 | }, 69 | |d| { 70 | for d in d { 71 | d.to_string(); 72 | } 73 | }, 74 | ) 75 | } 76 | 77 | pub fn bench_to_string_64(d: Decimal64, b: &mut Bencher) { 78 | b.iter_with_setup( 79 | || { 80 | let mut cx = Context::::default(); 81 | [-50, 0, 50] 82 | .iter() 83 | .map(|exp| { 84 | let mut d = d.clone(); 85 | cx.set_exponent(&mut d, *exp); 86 | d 87 | }) 88 | .collect::>() 89 | }, 90 | |d| { 91 | for d in d { 92 | d.to_string(); 93 | } 94 | }, 95 | ) 96 | } 97 | 98 | pub fn bench_standard_notation_string(d: Decimal128, b: &mut Bencher) { 99 | b.iter_with_setup( 100 | || { 101 | let mut cx = Context::::default(); 102 | [-50, 0, 50] 103 | .iter() 104 | .map(|exp| { 105 | let mut d = d.clone(); 106 | cx.set_exponent(&mut d, *exp); 107 | d 108 | }) 109 | .collect::>() 110 | }, 111 | |d| { 112 | for d in d { 113 | d.to_standard_notation_string(); 114 | } 115 | }, 116 | ) 117 | } 118 | 119 | pub fn bench_standard_notation_string_64(d: Decimal64, b: &mut Bencher) { 120 | b.iter_with_setup( 121 | || { 122 | let mut cx = Context::::default(); 123 | [-50, 0, 50] 124 | .iter() 125 | .map(|exp| { 126 | let mut d = d.clone(); 127 | cx.set_exponent(&mut d, *exp); 128 | d 129 | }) 130 | .collect::>() 131 | }, 132 | |d| { 133 | for d in d { 134 | d.to_standard_notation_string(); 135 | } 136 | }, 137 | ) 138 | } 139 | 140 | pub fn bench_print(c: &mut Criterion) { 141 | let mut rng = thread_rng(); 142 | let mut cx = Context::::default(); 143 | let d128 = cx.from_i128(rng.gen()); 144 | c.bench_function("to_string_dec128", |b| bench_to_string(d128.clone(), b)); 145 | let mut rng = thread_rng(); 146 | let mut cx = Context::::default(); 147 | let d128 = cx.from_i128(rng.gen()); 148 | c.bench_function("to_standard_notation_string_dec128", |b| { 149 | bench_standard_notation_string(d128, b) 150 | }); 151 | let mut rng = thread_rng(); 152 | let mut cx = Context::::default(); 153 | let d64 = cx.from_i64(rng.gen()); 154 | c.bench_function("to_string_dec64", |b| bench_to_string_64(d64.clone(), b)); 155 | let mut rng = thread_rng(); 156 | let mut cx = Context::::default(); 157 | let d64 = cx.from_i64(rng.gen()); 158 | c.bench_function("to_standard_notation_string_dec64", |b| { 159 | bench_standard_notation_string_64(d64, b) 160 | }); 161 | } 162 | 163 | pub fn bench_try_into_primitive(d: Decimal<13>, b: &mut Bencher) { 164 | b.iter_with_setup( 165 | || { 166 | [-1, 0, 1] 167 | .iter() 168 | .map(|exp| { 169 | let mut d = d.clone(); 170 | d.set_exponent(*exp); 171 | d 172 | }) 173 | .collect::>() 174 | }, 175 | |v| { 176 | for d in v { 177 | let _ = i128::try_from(d); 178 | } 179 | }, 180 | ) 181 | } 182 | 183 | pub fn bench_tryinto_primitive(c: &mut Criterion) { 184 | let mut rng = thread_rng(); 185 | let d: Decimal<13> = i32::into(rng.gen()); 186 | c.bench_function("bench_try_into_primitive", |b| { 187 | bench_try_into_primitive(d.clone(), b) 188 | }); 189 | } 190 | 191 | criterion_group!( 192 | benches, 193 | bench_decode, 194 | bench_print, 195 | bench_tryinto_primitive, 196 | bench_parse 197 | ); 198 | criterion_main!(benches); 199 | -------------------------------------------------------------------------------- /testdata/abs.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- abs.decTest -- decimal absolute value -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | -- This set of tests primarily tests the existence of the operator. 22 | -- Additon, subtraction, rounding, and more overflows are tested 23 | -- elsewhere. 24 | 25 | precision: 9 26 | rounding: half_up 27 | maxExponent: 384 28 | minexponent: -383 29 | extended: 1 30 | 31 | absx001 abs '1' -> '1' 32 | absx002 abs '-1' -> '1' 33 | absx003 abs '1.00' -> '1.00' 34 | absx004 abs '-1.00' -> '1.00' 35 | absx005 abs '0' -> '0' 36 | absx006 abs '0.00' -> '0.00' 37 | absx007 abs '00.0' -> '0.0' 38 | absx008 abs '00.00' -> '0.00' 39 | absx009 abs '00' -> '0' 40 | 41 | absx010 abs '-2' -> '2' 42 | absx011 abs '2' -> '2' 43 | absx012 abs '-2.00' -> '2.00' 44 | absx013 abs '2.00' -> '2.00' 45 | absx014 abs '-0' -> '0' 46 | absx015 abs '-0.00' -> '0.00' 47 | absx016 abs '-00.0' -> '0.0' 48 | absx017 abs '-00.00' -> '0.00' 49 | absx018 abs '-00' -> '0' 50 | 51 | absx020 abs '-2000000' -> '2000000' 52 | absx021 abs '2000000' -> '2000000' 53 | precision: 7 54 | absx022 abs '-2000000' -> '2000000' 55 | absx023 abs '2000000' -> '2000000' 56 | precision: 6 57 | absx024 abs '-2000000' -> '2.00000E+6' Rounded 58 | absx025 abs '2000000' -> '2.00000E+6' Rounded 59 | precision: 3 60 | absx026 abs '-2000000' -> '2.00E+6' Rounded 61 | absx027 abs '2000000' -> '2.00E+6' Rounded 62 | 63 | absx030 abs '+0.1' -> '0.1' 64 | absx031 abs '-0.1' -> '0.1' 65 | absx032 abs '+0.01' -> '0.01' 66 | absx033 abs '-0.01' -> '0.01' 67 | absx034 abs '+0.001' -> '0.001' 68 | absx035 abs '-0.001' -> '0.001' 69 | absx036 abs '+0.000001' -> '0.000001' 70 | absx037 abs '-0.000001' -> '0.000001' 71 | absx038 abs '+0.000000000001' -> '1E-12' 72 | absx039 abs '-0.000000000001' -> '1E-12' 73 | 74 | -- examples from decArith 75 | precision: 9 76 | absx040 abs '2.1' -> '2.1' 77 | absx041 abs '-100' -> '100' 78 | absx042 abs '101.5' -> '101.5' 79 | absx043 abs '-101.5' -> '101.5' 80 | 81 | -- more fixed, potential LHS swaps/overlays if done by subtract 0 82 | precision: 9 83 | absx060 abs '-56267E-10' -> '0.0000056267' 84 | absx061 abs '-56267E-5' -> '0.56267' 85 | absx062 abs '-56267E-2' -> '562.67' 86 | absx063 abs '-56267E-1' -> '5626.7' 87 | absx065 abs '-56267E-0' -> '56267' 88 | 89 | -- overflow tests 90 | maxexponent: 999999999 91 | minexponent: -999999999 92 | precision: 3 93 | absx120 abs 9.999E+999999999 -> Infinity Inexact Overflow Rounded 94 | 95 | -- subnormals and underflow 96 | precision: 3 97 | maxexponent: 999 98 | minexponent: -999 99 | absx210 abs 1.00E-999 -> 1.00E-999 100 | absx211 abs 0.1E-999 -> 1E-1000 Subnormal 101 | absx212 abs 0.10E-999 -> 1.0E-1000 Subnormal 102 | absx213 abs 0.100E-999 -> 1.0E-1000 Subnormal Rounded 103 | absx214 abs 0.01E-999 -> 1E-1001 Subnormal 104 | -- next is rounded to Emin 105 | absx215 abs 0.999E-999 -> 1.00E-999 Inexact Rounded Subnormal Underflow 106 | absx216 abs 0.099E-999 -> 1.0E-1000 Inexact Rounded Subnormal Underflow 107 | absx217 abs 0.009E-999 -> 1E-1001 Inexact Rounded Subnormal Underflow 108 | absx218 abs 0.001E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped 109 | absx219 abs 0.0009E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped 110 | absx220 abs 0.0001E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped 111 | 112 | absx230 abs -1.00E-999 -> 1.00E-999 113 | absx231 abs -0.1E-999 -> 1E-1000 Subnormal 114 | absx232 abs -0.10E-999 -> 1.0E-1000 Subnormal 115 | absx233 abs -0.100E-999 -> 1.0E-1000 Subnormal Rounded 116 | absx234 abs -0.01E-999 -> 1E-1001 Subnormal 117 | -- next is rounded to Emin 118 | absx235 abs -0.999E-999 -> 1.00E-999 Inexact Rounded Subnormal Underflow 119 | absx236 abs -0.099E-999 -> 1.0E-1000 Inexact Rounded Subnormal Underflow 120 | absx237 abs -0.009E-999 -> 1E-1001 Inexact Rounded Subnormal Underflow 121 | absx238 abs -0.001E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped 122 | absx239 abs -0.0009E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped 123 | absx240 abs -0.0001E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped 124 | 125 | -- long operand tests 126 | maxexponent: 999 127 | minexponent: -999 128 | precision: 9 129 | absx301 abs 12345678000 -> 1.23456780E+10 Rounded 130 | absx302 abs 1234567800 -> 1.23456780E+9 Rounded 131 | absx303 abs 1234567890 -> 1.23456789E+9 Rounded 132 | absx304 abs 1234567891 -> 1.23456789E+9 Inexact Rounded 133 | absx305 abs 12345678901 -> 1.23456789E+10 Inexact Rounded 134 | absx306 abs 1234567896 -> 1.23456790E+9 Inexact Rounded 135 | 136 | precision: 15 137 | absx321 abs 12345678000 -> 12345678000 138 | absx322 abs 1234567800 -> 1234567800 139 | absx323 abs 1234567890 -> 1234567890 140 | absx324 abs 1234567891 -> 1234567891 141 | absx325 abs 12345678901 -> 12345678901 142 | absx326 abs 1234567896 -> 1234567896 143 | 144 | 145 | -- Specials 146 | precision: 9 147 | 148 | -- specials 149 | absx520 abs 'Inf' -> 'Infinity' 150 | absx521 abs '-Inf' -> 'Infinity' 151 | absx522 abs NaN -> NaN 152 | absx523 abs sNaN -> NaN Invalid_operation 153 | absx524 abs NaN22 -> NaN22 154 | absx525 abs sNaN33 -> NaN33 Invalid_operation 155 | absx526 abs -NaN22 -> -NaN22 156 | absx527 abs -sNaN33 -> -NaN33 Invalid_operation 157 | 158 | -- Null tests 159 | absx900 abs # -> NaN Invalid_operation 160 | 161 | -------------------------------------------------------------------------------- /testdata/ddNextPlus.decTest: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | -- ddNextPlus.decTest -- decDouble next that is greater [754r nextup] -- 3 | -- Copyright (c) Mike Cowlishaw, 1981, 2010. All rights reserved. -- 4 | -- Parts copyright (c) IBM Corporation, 1981, 2008. -- 5 | ------------------------------------------------------------------------ 6 | -- Please see the document "General Decimal Arithmetic Testcases" -- 7 | -- at http://speleotrove.com/decimal for the description of -- 8 | -- these testcases. -- 9 | -- -- 10 | -- These testcases are experimental ('beta' versions), and they -- 11 | -- may contain errors. They are offered on an as-is basis. In -- 12 | -- particular, achieving the same results as the tests here is not -- 13 | -- a guarantee that an implementation complies with any Standard -- 14 | -- or specification. The tests are not exhaustive. -- 15 | -- -- 16 | -- Please send comments, suggestions, and corrections to the author: -- 17 | -- Mike Cowlishaw, mfc@speleotrove.com -- 18 | ------------------------------------------------------------------------ 19 | version: 2.62 20 | 21 | -- All operands and results are decDoubles. 22 | precision: 16 23 | maxExponent: 384 24 | minExponent: -383 25 | extended: 1 26 | clamp: 1 27 | rounding: half_even 28 | 29 | ddnextp001 nextplus 0.9999999999999995 -> 0.9999999999999996 30 | ddnextp002 nextplus 0.9999999999999996 -> 0.9999999999999997 31 | ddnextp003 nextplus 0.9999999999999997 -> 0.9999999999999998 32 | ddnextp004 nextplus 0.9999999999999998 -> 0.9999999999999999 33 | ddnextp005 nextplus 0.9999999999999999 -> 1.000000000000000 34 | ddnextp006 nextplus 1.000000000000000 -> 1.000000000000001 35 | ddnextp007 nextplus 1.0 -> 1.000000000000001 36 | ddnextp008 nextplus 1 -> 1.000000000000001 37 | ddnextp009 nextplus 1.000000000000001 -> 1.000000000000002 38 | ddnextp010 nextplus 1.000000000000002 -> 1.000000000000003 39 | ddnextp011 nextplus 1.000000000000003 -> 1.000000000000004 40 | ddnextp012 nextplus 1.000000000000004 -> 1.000000000000005 41 | ddnextp013 nextplus 1.000000000000005 -> 1.000000000000006 42 | ddnextp014 nextplus 1.000000000000006 -> 1.000000000000007 43 | ddnextp015 nextplus 1.000000000000007 -> 1.000000000000008 44 | ddnextp016 nextplus 1.000000000000008 -> 1.000000000000009 45 | ddnextp017 nextplus 1.000000000000009 -> 1.000000000000010 46 | ddnextp018 nextplus 1.000000000000010 -> 1.000000000000011 47 | ddnextp019 nextplus 1.000000000000011 -> 1.000000000000012 48 | 49 | ddnextp021 nextplus -0.9999999999999995 -> -0.9999999999999994 50 | ddnextp022 nextplus -0.9999999999999996 -> -0.9999999999999995 51 | ddnextp023 nextplus -0.9999999999999997 -> -0.9999999999999996 52 | ddnextp024 nextplus -0.9999999999999998 -> -0.9999999999999997 53 | ddnextp025 nextplus -0.9999999999999999 -> -0.9999999999999998 54 | ddnextp026 nextplus -1.000000000000000 -> -0.9999999999999999 55 | ddnextp027 nextplus -1.0 -> -0.9999999999999999 56 | ddnextp028 nextplus -1 -> -0.9999999999999999 57 | ddnextp029 nextplus -1.000000000000001 -> -1.000000000000000 58 | ddnextp030 nextplus -1.000000000000002 -> -1.000000000000001 59 | ddnextp031 nextplus -1.000000000000003 -> -1.000000000000002 60 | ddnextp032 nextplus -1.000000000000004 -> -1.000000000000003 61 | ddnextp033 nextplus -1.000000000000005 -> -1.000000000000004 62 | ddnextp034 nextplus -1.000000000000006 -> -1.000000000000005 63 | ddnextp035 nextplus -1.000000000000007 -> -1.000000000000006 64 | ddnextp036 nextplus -1.000000000000008 -> -1.000000000000007 65 | ddnextp037 nextplus -1.000000000000009 -> -1.000000000000008 66 | ddnextp038 nextplus -1.000000000000010 -> -1.000000000000009 67 | ddnextp039 nextplus -1.000000000000011 -> -1.000000000000010 68 | ddnextp040 nextplus -1.000000000000012 -> -1.000000000000011 69 | 70 | -- Zeros 71 | ddnextp100 nextplus 0 -> 1E-398 72 | ddnextp101 nextplus 0.00 -> 1E-398 73 | ddnextp102 nextplus 0E-300 -> 1E-398 74 | ddnextp103 nextplus 0E+300 -> 1E-398 75 | ddnextp104 nextplus 0E+30000 -> 1E-398 76 | ddnextp105 nextplus -0 -> 1E-398 77 | ddnextp106 nextplus -0.00 -> 1E-398 78 | ddnextp107 nextplus -0E-300 -> 1E-398 79 | ddnextp108 nextplus -0E+300 -> 1E-398 80 | ddnextp109 nextplus -0E+30000 -> 1E-398 81 | 82 | -- specials 83 | ddnextp150 nextplus Inf -> Infinity 84 | ddnextp151 nextplus -Inf -> -9.999999999999999E+384 85 | ddnextp152 nextplus NaN -> NaN 86 | ddnextp153 nextplus sNaN -> NaN Invalid_operation 87 | ddnextp154 nextplus NaN77 -> NaN77 88 | ddnextp155 nextplus sNaN88 -> NaN88 Invalid_operation 89 | ddnextp156 nextplus -NaN -> -NaN 90 | ddnextp157 nextplus -sNaN -> -NaN Invalid_operation 91 | ddnextp158 nextplus -NaN77 -> -NaN77 92 | ddnextp159 nextplus -sNaN88 -> -NaN88 Invalid_operation 93 | 94 | -- Nmax, Nmin, Ntiny, subnormals 95 | ddnextp170 nextplus -9.999999999999999E+384 -> -9.999999999999998E+384 96 | ddnextp171 nextplus -9.999999999999998E+384 -> -9.999999999999997E+384 97 | ddnextp172 nextplus -1E-383 -> -9.99999999999999E-384 98 | ddnextp173 nextplus -1.000000000000000E-383 -> -9.99999999999999E-384 99 | ddnextp174 nextplus -9E-398 -> -8E-398 100 | ddnextp175 nextplus -9.9E-397 -> -9.8E-397 101 | ddnextp176 nextplus -9.99999999999E-387 -> -9.99999999998E-387 102 | ddnextp177 nextplus -9.99999999999999E-384 -> -9.99999999999998E-384 103 | ddnextp178 nextplus -9.99999999999998E-384 -> -9.99999999999997E-384 104 | ddnextp179 nextplus -9.99999999999997E-384 -> -9.99999999999996E-384 105 | ddnextp180 nextplus -0E-398 -> 1E-398 106 | ddnextp181 nextplus -1E-398 -> -0E-398 107 | ddnextp182 nextplus -2E-398 -> -1E-398 108 | 109 | ddnextp183 nextplus 0E-398 -> 1E-398 110 | ddnextp184 nextplus 1E-398 -> 2E-398 111 | ddnextp185 nextplus 2E-398 -> 3E-398 112 | ddnextp186 nextplus 10E-398 -> 1.1E-397 113 | ddnextp187 nextplus 100E-398 -> 1.01E-396 114 | ddnextp188 nextplus 100000E-398 -> 1.00001E-393 115 | ddnextp189 nextplus 1.00000000000E-383 -> 1.000000000000001E-383 116 | ddnextp190 nextplus 1.000000000000000E-383 -> 1.000000000000001E-383 117 | ddnextp191 nextplus 1E-383 -> 1.000000000000001E-383 118 | ddnextp192 nextplus 9.999999999999998E+384 -> 9.999999999999999E+384 119 | ddnextp193 nextplus 9.999999999999999E+384 -> Infinity 120 | 121 | -- Null tests 122 | ddnextp900 nextplus # -> NaN Invalid_operation 123 | 124 | -------------------------------------------------------------------------------- /decnumber-sys/decnumber/decQuad.c: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------ */ 2 | /* decQuad.c -- decQuad operations module */ 3 | /* ------------------------------------------------------------------ */ 4 | /* Copyright (c) IBM Corporation, 2000, 2010. All rights reserved. */ 5 | /* */ 6 | /* This software is made available under the terms of the */ 7 | /* ICU License -- ICU 1.8.1 and later. */ 8 | /* */ 9 | /* The description and User's Guide ("The decNumber C Library") for */ 10 | /* this software is included in the package as decNumber.pdf. This */ 11 | /* document is also available in HTML, together with specifications, */ 12 | /* testcases, and Web links, on the General Decimal Arithmetic page. */ 13 | /* */ 14 | /* Please send comments, suggestions, and corrections to the author: */ 15 | /* mfc@uk.ibm.com */ 16 | /* Mike Cowlishaw, IBM Fellow */ 17 | /* IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK */ 18 | /* ------------------------------------------------------------------ */ 19 | /* This module comprises decQuad operations (including conversions) */ 20 | /* ------------------------------------------------------------------ */ 21 | 22 | 23 | /* Constant mappings for shared code */ 24 | #define DECPMAX DECQUAD_Pmax 25 | #define DECEMIN DECQUAD_Emin 26 | #define DECEMAX DECQUAD_Emax 27 | #define DECEMAXD DECQUAD_EmaxD 28 | #define DECBYTES DECQUAD_Bytes 29 | #define DECSTRING DECQUAD_String 30 | #define DECECONL DECQUAD_EconL 31 | #define DECBIAS DECQUAD_Bias 32 | #define DECLETS DECQUAD_Declets 33 | #define DECQTINY (-DECQUAD_Bias) 34 | 35 | /* Type and function mappings for shared code */ 36 | #define decFloat decQuad // Type name 37 | 38 | // Utilities and conversions (binary results, extractors, etc.) 39 | #define decFloatFromBCD decQuadFromBCD 40 | #define decFloatFromInt32 decQuadFromInt32 41 | #define decFloatFromPacked decQuadFromPacked 42 | #define decFloatFromPackedChecked decQuadFromPackedChecked 43 | #define decFloatFromString decQuadFromString 44 | #define decFloatFromUInt32 decQuadFromUInt32 45 | #define decFloatFromWider decQuadFromWider 46 | #define decFloatGetCoefficient decQuadGetCoefficient 47 | #define decFloatGetExponent decQuadGetExponent 48 | #define decFloatSetCoefficient decQuadSetCoefficient 49 | #define decFloatSetExponent decQuadSetExponent 50 | #define decFloatShow decQuadShow 51 | #define decFloatToBCD decQuadToBCD 52 | #define decFloatToEngString decQuadToEngString 53 | #define decFloatToInt32 decQuadToInt32 54 | #define decFloatToInt32Exact decQuadToInt32Exact 55 | #define decFloatToPacked decQuadToPacked 56 | #define decFloatToString decQuadToString 57 | #define decFloatToUInt32 decQuadToUInt32 58 | #define decFloatToUInt32Exact decQuadToUInt32Exact 59 | #define decFloatToWider decQuadToWider 60 | #define decFloatZero decQuadZero 61 | 62 | // Computational (result is a decFloat) 63 | #define decFloatAbs decQuadAbs 64 | #define decFloatAdd decQuadAdd 65 | #define decFloatAnd decQuadAnd 66 | #define decFloatDivide decQuadDivide 67 | #define decFloatDivideInteger decQuadDivideInteger 68 | #define decFloatFMA decQuadFMA 69 | #define decFloatInvert decQuadInvert 70 | #define decFloatLogB decQuadLogB 71 | #define decFloatMax decQuadMax 72 | #define decFloatMaxMag decQuadMaxMag 73 | #define decFloatMin decQuadMin 74 | #define decFloatMinMag decQuadMinMag 75 | #define decFloatMinus decQuadMinus 76 | #define decFloatMultiply decQuadMultiply 77 | #define decFloatNextMinus decQuadNextMinus 78 | #define decFloatNextPlus decQuadNextPlus 79 | #define decFloatNextToward decQuadNextToward 80 | #define decFloatOr decQuadOr 81 | #define decFloatPlus decQuadPlus 82 | #define decFloatQuantize decQuadQuantize 83 | #define decFloatReduce decQuadReduce 84 | #define decFloatRemainder decQuadRemainder 85 | #define decFloatRemainderNear decQuadRemainderNear 86 | #define decFloatRotate decQuadRotate 87 | #define decFloatScaleB decQuadScaleB 88 | #define decFloatShift decQuadShift 89 | #define decFloatSubtract decQuadSubtract 90 | #define decFloatToIntegralValue decQuadToIntegralValue 91 | #define decFloatToIntegralExact decQuadToIntegralExact 92 | #define decFloatXor decQuadXor 93 | 94 | // Comparisons 95 | #define decFloatCompare decQuadCompare 96 | #define decFloatCompareSignal decQuadCompareSignal 97 | #define decFloatCompareTotal decQuadCompareTotal 98 | #define decFloatCompareTotalMag decQuadCompareTotalMag 99 | 100 | // Copies 101 | #define decFloatCanonical decQuadCanonical 102 | #define decFloatCopy decQuadCopy 103 | #define decFloatCopyAbs decQuadCopyAbs 104 | #define decFloatCopyNegate decQuadCopyNegate 105 | #define decFloatCopySign decQuadCopySign 106 | 107 | // Non-computational 108 | #define decFloatClass decQuadClass 109 | #define decFloatClassString decQuadClassString 110 | #define decFloatDigits decQuadDigits 111 | #define decFloatIsCanonical decQuadIsCanonical 112 | #define decFloatIsFinite decQuadIsFinite 113 | #define decFloatIsInfinite decQuadIsInfinite 114 | #define decFloatIsInteger decQuadIsInteger 115 | #define decFloatIsLogical decQuadIsLogical 116 | #define decFloatIsNaN decQuadIsNaN 117 | #define decFloatIsNegative decQuadIsNegative 118 | #define decFloatIsNormal decQuadIsNormal 119 | #define decFloatIsPositive decQuadIsPositive 120 | #define decFloatIsSignaling decQuadIsSignaling 121 | #define decFloatIsSignalling decQuadIsSignalling 122 | #define decFloatIsSigned decQuadIsSigned 123 | #define decFloatIsSubnormal decQuadIsSubnormal 124 | #define decFloatIsZero decQuadIsZero 125 | #define decFloatRadix decQuadRadix 126 | #define decFloatSameQuantum decQuadSameQuantum 127 | #define decFloatVersion decQuadVersion 128 | 129 | /* And now the code itself */ 130 | #include "decContext.h" // public includes 131 | #include "decQuad.h" // .. 132 | #include "decNumberLocal.h" // local includes (need DECPMAX) 133 | #include "decCommon.c" // non-arithmetic decFloat routines 134 | #include "decBasic.c" // basic formats routines 135 | 136 | --------------------------------------------------------------------------------