1 stable release

1.0.0 Feb 5, 2024

#2515 in Algorithms

Download history 12/week @ 2024-08-04 1/week @ 2024-08-11 18/week @ 2024-09-08 19/week @ 2024-09-15 38/week @ 2024-09-22 14/week @ 2024-09-29 21/week @ 2024-10-06 10/week @ 2024-10-13 34/week @ 2024-10-20 83/week @ 2024-10-27 29/week @ 2024-11-03

157 downloads per month

MIT/Apache

9KB
169 lines

Float multiplication to integer part

Crate informations License Documentation

This library provides the mul_to_int function for f32 and f64 that allows one to multiply two float numbers and keep the integer part of the result without loss of precision. The fractional part is truncated.

Usage

Just import the FloatMulToInt trait to have access to the mul_to_int method.

use fmul_to_int::FloatMulToInt;

assert_eq!(11.0f64.mul_to_int(1_000_000_000.0).unwrap(), 11_000_000_000i128);

lib.rs:

This library provides the mul_to_int function for f32 and f64 that allows one to multiply two float numbers and keep the integer part of the result without loss of precision. The fractional part is truncated.

Usage

Just import the FloatMulToInt trait to have access to the mul_to_int method.

use fmul_to_int::FloatMulToInt;

assert_eq!(11.0f64.mul_to_int(1_000_000_000.0).unwrap(), 11_000_000_000i128);

No runtime deps

Features