Comments (8)
round
is the function that can round fractional part of a number.
What's the value of this ROUNDING_MODE
?
from astro-float.
Also, rounding will not change exponent of a number, unless there was overflow during rounding.
from astro-float.
What's the value of this ROUNDING_MODE ?
It is set to none - RoundingMode::None
from astro-float.
Ok, so seems like the only way is to read the mantissa after rounding as a string. Drop off digits after decimal as per the exponent. Then parse the resulting string of digits into BigUint. Do you think there's a better way to do this?
from astro-float.
This is what I came up with:
let mut consts = Consts::new().unwrap();
let mut value = AstroBFloat::from(1.2);
let (sign, radix_repr, mut ex) = value
.round(0, ROUNDING_MODE)
.convert_to_radix(astro_float::Radix::Dec, ROUNDING_MODE, &mut consts)
.unwrap();
if ex < 0 {
ex = 0;
}
// Assume sign is always positive
let value_biguint = BigUint::from_radix_be(&radix_repr[..ex as usize], 10).unwrap();
from astro-float.
round()
with RoundingMode::None
has no effect: docs.
The most efficient way in my opinion is to get raw parts of big float, and then construct big integer from the mantissa slice after accomplishing required bit shift.
from astro-float.
Sorry for late reply!
Is this what you had in mind ?
// PRECISION = 256
// MANTISSA_LEN = 4
let value = value.0.clone();
let (raw, _, s, _, _) = value.as_raw_parts().unwrap();
let exponent = value.exponent().unwrap();
let mut bits = exponent;
let mut index = MATISSA_LEN - 1;
let mut res = BigInt::zero();
while bits > 0 {
res += (BigInt::from_u64(raw[index as usize]).unwrap())
<< (astro_float::WORD_BIT_SIZE * index);
bits -= astro_float::WORD_BIT_SIZE as i32;
index -= 1;
}
res >>= (PRECISION as i32) - exponent;
res = if s.is_negative() { res.neg() } else { res }
from astro-float.
Closing the issue as it is not a bug.
from astro-float.
Related Issues (19)
- Improve performance of printing and parsing of decimal. HOT 1
- Replace SmallVec with Vec
- Review Unsafe code sections.
- Improve performance of Mantissa::pow_mod HOT 1
- Improve performance of Mantissa::div_short
- Improve performance of Mantissa::mul_short
- Implement AGM algorithms for the logarithm.
- Implement ^ operator in expr macro HOT 1
- Proposal for a public `BigFloat::to_f64` HOT 8
- Typedefs Don't Support non-x86 HOT 2
- Values 10x smaller with BigFloat::from_f64(); HOT 1
- Addition of specific values in `expr!` hangs astro_float HOT 5
- `sinh` of a large negative number returns positive infinity HOT 1
- Unexpected rounding behaviour. HOT 5
- Add a `BigFloat` with const generic precision
- Use target pointer width rather than x86 HOT 1
- Store the mantissa as a `Box<[Word]>` rather than a vector HOT 1
- Add convenience functions for conversion to primitive integer types. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from astro-float.