Serving the Quantitative Finance Community

  • 1
  • 4
  • 5
  • 6
  • 7
  • 8
 
User avatar
Cuchulainn
Topic Author
Posts: 20250
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

User feedback Mr. sitmo's prng

December 24th, 2013, 10:15 am

QuoteOriginally posted by: outrunQuoteOriginally posted by: CuchulainnQuoteI don't get the delegate:See the example again Mon Dec 23, 13 08:36 PMI see.RngDelegate rand = prng.NextDouble;is likestd::function rand = enginine.operator();I though that rand was a float (the return type of the NextDouble member function), but you're passing an engine to BoxMullerII.Nice!There are two issues that are confusing (there are two 'levels'):1. Server code e.g. the Box-Muller that contains a delegate type [std::function rand = engine.operator();]2. Clienct code that must assign the delegate type to a target method [RngDelegate rand = prng.NextDouble;]So the two C++ and C# are exactly the same but numerics in .NET with generic types is a non-starter. So I use double.
Last edited by Cuchulainn on December 23rd, 2013, 11:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Topic Author
Posts: 20250
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

User feedback Mr. sitmo's prng

December 24th, 2013, 10:21 am

Indeed Bingo!Here is another example in the same sphere to emulate STL algos in C# and the delegate idea againpublic delegate bool Condition<T> (T value); // ~ std::function() declaration
Last edited by Cuchulainn on December 23rd, 2013, 11:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Topic Author
Posts: 20250
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

User feedback Mr. sitmo's prng

December 24th, 2013, 10:35 am

QuoteOriginally posted by: outrunah,.. I now see this at the toppublic delegate double RngDelegate();*that's* the generic bitIndeed. And you call it as a function ... As with std::function, all that matters for compatibility is function signature, i.e. input args return type // BTW there is no STL-like stuff in C# (some LINQ but that's another ball game)
Last edited by Cuchulainn on December 23rd, 2013, 11:00 pm, edited 1 time in total.