Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when passing {integer}::MIN to any of the resizing functions #15

Closed
AaronKutch opened this issue Apr 9, 2018 · 5 comments
Closed

Comments

@AaronKutch
Copy link
Contributor

AaronKutch commented Apr 9, 2018

extern crate apint;
use apint::{ApInt, BitWidth};
use std::i128;

fn main() {
    println!(
        "{:?}",
        ApInt::from_i128(i128::MAX).into_sign_extend(BitWidth::new(256).unwrap()),
    );
    println!(
        "{:?}",
        ApInt::from_i128(i128::MIN).into_sign_extend(BitWidth::new(256).unwrap()),
    );
}

If I were you, I would add tests for the problematic {integer}::MIN values everywhere applicable.

Also, I found this in the documentation:

pub fn from_i128(val: i128) -> ApInt
[src]
[−]
Creates a new ApInt from a given i128 value with a bit-width of 64.
pub fn from_u128(val: u128) -> ApInt
[src]
[−]
Creates a new ApInt from a given u128 value with a bit-width of 64.

It should be 128 not 64.

Also, now that i128 is stabilized (except for repr(i128)), check that the implementation and docs of all the i128 stuff is also correct.

This crate perfectly fits my use case (and I think that it is much, much better than the num_bigint crate in general), but there is some unimplemented! stuff in the multiply and divide functions that prevents me from using it.

@Robbepop
Copy link
Owner

Robbepop commented Apr 10, 2018

Thank you for your bug report!
I will look into this and comment more thoroughly tomorrow - it is very late here. ;)

@AaronKutch
Copy link
Contributor Author

My application relies on there being no edge cases or unexpected behavior, so you can expect more in the future. Do have plans for fixing the unimplemented parts in the next month or so? I can perform inefficient mult and div functions on my side so actually I can start using the crate right away. I am using your crate to make large integers with behaviors just like the primitives. Also, can you make a function that returns the bit width of the ApInt? It would make some things easier for me.

@Robbepop
Copy link
Owner

You can get the bit width of an ApInt, Int or Uint instance by using the Width trait with its width method. For this, however, you have to explicitely import (use) it with use apint::Width; otherwise it is not visible to you. This is unergonomic and might improve in future versions.

I am using the apint crate myself in stevia so it is also important for my other project that the apint crate improves. :)

@Robbepop
Copy link
Owner

Robbepop commented Apr 10, 2018

I will try to fix the reported bugs in the apint crate next weekend (maybe even earlier) and also try to implement multiplication and division routines for large apint instances as well. However, PRs are generally welcome, too. :)

Robbepop added a commit that referenced this issue Apr 10, 2018
The bug hasn't been fixed yet though.
@Robbepop
Copy link
Owner

I have fixed the reported bug in version 0.1.0 of the crate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants