Serving the Quantitative Finance Community

User avatar
Topic Author
Posts: 711
Joined: June 6th, 2005, 9:49 am

High Precision FP - Prototyping MSVC

December 8th, 2012, 6:46 pm

Hi,what is the easiest way to run existing c++ code in MSVC2010 with higher floating point precision than double ? I just want to see if it is worthwhile to move into that direction, so I do not want to change the compiler / use some external library.Any experience ?Thanks a lotPeter
User avatar
Posts: 2526
Joined: April 29th, 2008, 4:55 pm

High Precision FP - Prototyping MSVC

December 8th, 2012, 7:50 pm ... ision/grep for 80 (as in 80-bit), extended (as in extended precision), long double, controlfp (as in _controlfp_s -- _PC_64 is the mask you're interested in), D3DCREATE_FPU_PRESERVEHere's a handy chart:
Last edited by Polter on December 7th, 2012, 11:00 pm, edited 1 time in total.
User avatar
Topic Author
Posts: 711
Joined: June 6th, 2005, 9:49 am

High Precision FP - Prototyping MSVC

December 9th, 2012, 10:42 am

thanks very interesting indeed. And helpful.
User avatar
Posts: 64298
Joined: July 16th, 2004, 7:38 am
Location: Drosophila melanogaster

Re: High Precision FP - Prototyping MSVC

December 27th, 2017, 12:30 pm

You can use Boost multiprecision. Here an example to compute [$]\pi[$].
BTW Archimedes of Syracuse probably invented Interval Arithmetic.

N, value: 20/3.141592653589662682701706171090774719985979379159334657412021084377287605362950884738001859546262235
Error: 3.9166728e-13
N, value: 40/3.141592653589793238462643264539730025868175440272163320532165222527356511645931880184364385214446692
Error: 3.5621932e-25
N, value: 60/3.141592653589793238462643383279502884089176205070734653848659243661099969287718976336684872480311458
Error: 3.2397958e-37
N, value: 80/3.14159265358979323846264338327950288419716939937500760173689723236079737032492766828422638159104739
Error: 2.9465771e-49
N, value: 100/3.141592653589793238462643383279502884197169399375105820974944502977939790038327551870396055373551631
Error: 2.6798963e-61
N, value: 120/3.141592653589793238462643383279502884197169399375105820974944592307816406204963949135527982537650455
Error: 2.4373515e-73
N, value: 140/3.141592653589793238462643383279502884197169399375105820974944592307816406286208998627960933400058354
Error: 2.2167583e-85
N, value: 160/3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117001
Error: 2.0161299e-97
N, value: 180/3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068
Error: 1.833314e-109
N, value: 200/3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068
Error: 3.6190453e-113
template <typename T>
 void ArchimedesPi(int N)
{ // N == number of iterations

 T three(3.0); T two(2.0);
 T an, anp1, bn, bnp1;
 an = 2.0*boost::multiprecision::sqrt(three); bn = T(three);

 for (int n = 1; n <= N; ++n)
 // Take harmonic and geometric means
 anp1 = two*an*bn / (an + bn); 
 bnp1 = boost::multiprecision::sqrt(bn*anp1); 

 an = anp1; bn = bnp1;

 std::cout << "N, value: " << std::setprecision(std::numeric_limits<T>::digits10)
 << N << "/" << bn << "\n\n";

 std::cout << "Error: " << std::setprecision(8)
 << boost::multiprecision::abs(bn - an) << "\n\n";

"Compatibility means deliberately repeating other people's mistakes."
David Wheeler