Skip to content

Commit 46eeb8a

Browse files
authored
Devel (#2)
* Drop allow dead_code * Fix a bug with 1-word mul/div * Fix commented out no_std * Version number bump
1 parent 0baca85 commit 46eeb8a

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fixed-bigint"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
authors = ["kaidokert <[email protected]>"]
55
edition = "2018"
66
description = """

src/fixeduint.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![allow(dead_code)]
21
// Copyright 2021 Google LLC
32
//
43
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -187,8 +186,10 @@ impl<T: MachineWord, const N: usize> FixedUInt<T, N> {
187186
fn from_doubleword(other: T::DoubleWord) -> Self {
188187
let mut ret = Self::zero();
189188
ret.array[0] = T::from_double(other);
190-
let tmp2 = other >> Self::WORD_BITS;
191-
ret.array[1] = T::from_double(tmp2);
189+
if N > 1 {
190+
let tmp2 = other >> Self::WORD_BITS;
191+
ret.array[1] = T::from_double(tmp2);
192+
}
192193
ret
193194
}
194195

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
//#![no_std]
15+
#![no_std]
1616

1717
//! A fixed-size big integer implementation, unsigned only.
1818
//! [FixedUInt] implements a [num_traits::PrimInt] trait, mimicking built-in `u8`, `u16` and `u32` types.

tests/mul_div.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@
1616
use fixed_bigint::FixedUInt as Bn;
1717

1818
use num_traits::{FromPrimitive, ToPrimitive};
19+
use std::ops::{Div, Mul};
1920

2021
#[test]
2122
fn test_mul() {
23+
let a: Bn<u8, 1> = 2u8.into();
24+
let b: Bn<u8, 1> = 3u8.into();
25+
assert_eq!(a * b, 6u8.into());
26+
assert_eq!(a.mul(b), 6u8.into());
27+
2228
let a = Bn::<u8, 2>::from_u64(3).unwrap();
2329
let b = Bn::<u8, 2>::from_u64(4).unwrap();
2430
let r = a * b;
@@ -62,6 +68,11 @@ fn test_mul() {
6268

6369
#[test]
6470
fn test_div() {
71+
let a: Bn<u8, 1> = 6u8.into();
72+
let b: Bn<u8, 1> = 3u8.into();
73+
assert_eq!(a / b, 2u8.into());
74+
assert_eq!(a.div(b), 2u8.into());
75+
6576
fn test_div_1<BN: num_traits::PrimInt>()
6677
where
6778
BN::FromStrRadixErr: core::fmt::Debug,

0 commit comments

Comments
 (0)