Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Crash when converting base-2 to base-10 floating-point number with manually set higher precision on 32-bit Windows targets #95

Copy link
Copy link

Description

@bambamboo15
Issue body actions

Hello! While I was making a simple fractal explorer, I stumbled across this.

The below minimal working example initializes a certain FBig<Zero, 2> then manually sets its precision. With with_base::<10>(), the operation internally crashes. This only happens on 32-bit targets: wasm32-unknown-unknown and i686-pc-windows-msvc reproduce this bug. With normal 64-bit targets the code executes perfectly.

use dashu::float::{FBig, round::mode::Zero};
use std::str::FromStr;

fn main() {
    let str = "-1.1111111111111101110010001101011001000101000110010100101001011010100101011101111101001011111000000110001101000111001011010100010000000110110111010000100101100011001110011101110101111101110000101010100001010010011111010010000010001011001111011010011110111001111001011100001101101011010011110100100110100111100110000010110010110010101011010010000010100100111001111110010011000000000101101111100001011000111111101000110011011101111010100000000100011010011011010000000111111110001110000010001100011000100111000100111011010100111101010111101001111011101010111100001100110001010010011";

    // Initialize a normal base-2 float, then convert it to base-10.
    let num = FBig::<Zero, 2>::from_str(str).unwrap();
    println!("precision: {}", num.precision());
    println!(
        "base-10 representation: {}",
        num.clone().with_base::<10>().value()
    );

    // Now set the original number's precision, and convert it to base-10.
    let num = num.with_precision(586).value();
    println!("precision: {}", num.precision());
    println!(
        "base-10 representation: {}",
        num.clone().with_base::<10>().value()
    );
}

32-bit output

precision: 578
base-10 representation: -1.9999661944503703041843468850635057967553124154072485151176192294480158424234268438137612977886891381228704640656094986435381057574477216648567249609280392009533217665484389
precision: 586

thread 'main' (19236) panicked at C:\_______\dashu-float-0.5.0\src\error.rs:94:5:
arithmetic operations with the infinity are not allowed!
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\i686-pc-windows-msvc\debug\dashu-bug.exe` (exit code: 101)

64-bit output

precision: 578
base-10 representation: -1.9999661944503703041843468850635057967553124154072485151176192294480158424234268438137612977886891381228704640656094986435381057574477216648567249609280392009533217665484389
precision: 586
base-10 representation: -1.9999661944503703041843468850635057967553124154072485151176192294480158424234268438137612977886891381228704640656094986435381057574477216648567249609280392009533217665484389886
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.