Skip to content

Commit

Permalink
Devel (#2)
Browse files Browse the repository at this point in the history
* Drop allow dead_code

* Fix a bug with 1-word mul/div

* Fix commented out no_std

* Version number bump
  • Loading branch information
kaidokert authored Apr 8, 2021
1 parent 0baca85 commit 46eeb8a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fixed-bigint"
version = "0.1.0"
version = "0.1.1"
authors = ["kaidokert <[email protected]>"]
edition = "2018"
description = """
Expand Down
7 changes: 4 additions & 3 deletions src/fixeduint.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(dead_code)]
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -187,8 +186,10 @@ impl<T: MachineWord, const N: usize> FixedUInt<T, N> {
fn from_doubleword(other: T::DoubleWord) -> Self {
let mut ret = Self::zero();
ret.array[0] = T::from_double(other);
let tmp2 = other >> Self::WORD_BITS;
ret.array[1] = T::from_double(tmp2);
if N > 1 {
let tmp2 = other >> Self::WORD_BITS;
ret.array[1] = T::from_double(tmp2);
}
ret
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//#![no_std]
#![no_std]

//! A fixed-size big integer implementation, unsigned only.
//! [FixedUInt] implements a [num_traits::PrimInt] trait, mimicking built-in `u8`, `u16` and `u32` types.
Expand Down
11 changes: 11 additions & 0 deletions tests/mul_div.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@
use fixed_bigint::FixedUInt as Bn;

use num_traits::{FromPrimitive, ToPrimitive};
use std::ops::{Div, Mul};

#[test]
fn test_mul() {
let a: Bn<u8, 1> = 2u8.into();
let b: Bn<u8, 1> = 3u8.into();
assert_eq!(a * b, 6u8.into());
assert_eq!(a.mul(b), 6u8.into());

let a = Bn::<u8, 2>::from_u64(3).unwrap();
let b = Bn::<u8, 2>::from_u64(4).unwrap();
let r = a * b;
Expand Down Expand Up @@ -62,6 +68,11 @@ fn test_mul() {

#[test]
fn test_div() {
let a: Bn<u8, 1> = 6u8.into();
let b: Bn<u8, 1> = 3u8.into();
assert_eq!(a / b, 2u8.into());
assert_eq!(a.div(b), 2u8.into());

fn test_div_1<BN: num_traits::PrimInt>()
where
BN::FromStrRadixErr: core::fmt::Debug,
Expand Down

0 comments on commit 46eeb8a

Please sign in to comment.