Serving the Quantitative Finance Community

 
User avatar
Cuchulainn
Topic Author
Posts: 20254
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

C++ quiz - Maths and acccuracy

November 30th, 2013, 7:36 pm

QuoteOriginally posted by: outrunWhy does this print 60?Because it has been programmed to do just that? QuoteIt is important to note that a postfix increment or decrement expression evaluates to the value of the expression prior to application of the respective operator. The increment or decrement operation occurs after the operand is evaluated. This issue arises only when the postfix increment or decrement operation occurs in the context of a larger expression.The tricky part is knowing when i++ kicks in, yes? GOTO harmful << ++ harmful
Last edited by Cuchulainn on November 29th, 2013, 11:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Topic Author
Posts: 20254
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

C++ quiz - Maths and acccuracy

December 2nd, 2013, 7:05 pm

11? Noedit: Yikes, missed {} does not compile on all compilers. So, 12?
Last edited by Cuchulainn on December 1st, 2013, 11:00 pm, edited 1 time in total.
 
User avatar
dd3
Posts: 4
Joined: June 8th, 2010, 9:02 am

C++ quiz - Maths and acccuracy

December 2nd, 2013, 8:56 pm

I was at an Intel conference a few days ago and there was a guy there who did CGI for films. He said they have to write their own maths libraries so that they get the same floating-point when they farm out work to their CPUs and GPUs. One little error can cascade down and ruin future image frames.
 
User avatar
Cuchulainn
Topic Author
Posts: 20254
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

C++ quiz - Maths and acccuracy

December 6th, 2013, 6:35 pm

Here's a problem involving composing functions f,g etc. from <cmath> Let's say x is a real on +- infinity. Can the function f(g(x)) ever underflow or overflow (or divide by zero)? e.g. std::exp(a * std::exp(-b * j)) for j = 1,...,N?Basically, what needs to be done to ensure we get no flow issues?
 
User avatar
Cuchulainn
Topic Author
Posts: 20254
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

C++ quiz - Maths and acccuracy

December 13th, 2013, 4:59 am

output?
 
User avatar
Cuchulainn
Topic Author
Posts: 20254
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

C++ quiz - Maths and acccuracy

December 13th, 2013, 8:34 am

QuoteOriginally posted by: outrunThat's trouble! It might even depend on the number of bits of the double type? I avoid that and replace that with interger loops, or with a stop condition that's dead in the middle x<0.35 :-)To get an exact answer we will need to look up the floating point arithmics rules and definitions.It's a nasty one, right? Just by looking at the code one would think the loop is executed 3 times.
 
User avatar
Cuchulainn
Topic Author
Posts: 20254
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

C++ quiz - Maths and acccuracy

May 15th, 2014, 7:31 am

I am not sure how widespread the use of continued fractions is in C libraries, but they do have some appealing properties. . maybe outrun's 1/3 can be written as a CF. tried getting my head around CF for exp(5) but I gave up.. you can generalise the code to sqrt(x) for any x.CF
Last edited by Cuchulainn on May 14th, 2014, 10:00 pm, edited 1 time in total.