Fractal Software > Programming

 Using boost::multiprecision::mpfr_float

(1/1)

LorenDB:
I'm making a fractal viewer (for now, Mandelbrot, Julia, and Burning Ship) that uses boost::multiprecision::mpfr_float. Does anybody know if this class automatically adjusts its precision? Or do I have to manually adjust, and if so, how should I go about doing that?

The code is available at https://github.com/LorenDB/fracture.

Thanks in advance.

Linkback: https://fractalforums.org/index.php?topic=4430.0

gerson:
Welcome to the forum.
Good news about your program.
waiting a windows binary release...

claude:
There are two ways of using Boost for this, one has fixed precision defined at compile time, the other has dynamic precision defined at runtime.  For the runtime method, you can use:


--- Code: ---typedef boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>> R;
R::default_precision(100);
R b;
// b has 100 decimal digits
b.precision(1000);
// b is rounded to 1000 decimal digits
b = 2;
b = sqrt(b);
// b contains sqrt(2) accurate to 1000 decimal digits
R::default_precision()
// returns 100
b::precision()
// returns 1000

--- End code ---

I'm not sure how e.g. operator+() and temporaries work with mixed precision operations, probably they use the default_precision.
You can use RAII to have a class that sets the default precision on construction and restores it to the previous value when it goes out of scope.

Note: Boost with dynamic precision can be a lot slower than using mpfr_add etc directly, though it's much more convenient.  This is due to memory allocation and deallocation for temporaries taking up time.  In et and KF I use a preprocessor/compiler to convert expressions to mpfr_ calls with temporary initialization and clearing floated outside the inner loops.

Oh, and if you're using threads you should clear the MPFR caches at thread exit to avoid leaks.  I'd hope the default precision is thread_local but I'm not 100% sure...

LorenDB:
@gerson: Thanks, good to be here. Binaries for Windows are probably a little ways out especially because I'm on Linux for a daily driver (although I have access to Windows if needed).

@claude: Thanks for the info; looks like a lot of stuff to think about. I had not noticed the class reference for some reason (stupid me!). I'll look into using precision() to set precision. I'll also check out the cache thing, since I am doing multithreaded.

Hopefully I'll get something figured out in the days to come.

Navigation

[0] Message Index

Go to full version
Powered by SMFPacks Rates (Facepunch) Mod
Powered by SMFPacks SEO Pro Mod | Sitemap
Powered by Advanced Topic Prefix Pro
Powered by SMFPacks Advanced Attachments Uploader Mod