0

This question is opposite to my another this question. I need to do opposite operation. I have c# decimal which I need to convert to this structure:

    public struct significand
    {
        public uint mantissa;  // or ulong
        public sbyte exponent;
    }

I pass this structure to c++ library via p/invoke later. How can I convert decimal to this structure? I guess probably I should use Decimal.GetBits method somehow? Or probably I can declare c++ structure some way so decimal will be automatically converted to it (i think they should be binary-compatible). Currently i'm using such c++ struct:

struct significand_t
{
uint32_t mantissa;
int8_t exponent;
};
Community
  • 1
  • 1
Oleg Vazhnev
  • 23,239
  • 54
  • 171
  • 305

1 Answers1

-1

have a look here about Binary floating point and .NET

you will find there a link to some sample code with will be useful for your case.

--r

macf00bar
  • 673
  • 1
  • 14
  • 32
  • Drilling down I did find the recommended link but it was dead, see the .zip links at the bottom of this useful article series: https://www.codeguru.com/csharp/csharp/cs_misc/mathematics/article.php/c9637/Floating-Point-in-NET-Part-I-Concepts-and-Formats.htm I'll post an answer when I've got it all figured out. – mhand Jun 15 '18 at 16:22
  • 1
    if your're talking about this (http://csharpindepth.com/Articles/General/FloatingPoint.aspx) link, it's not dead and I have no idea how you're comment relates to my sort-of-answer (I know, I should have posted the link only as a comment myself instead of and answer) – macf00bar Jun 18 '18 at 08:42
  • 1
    I actually overlooked the sample code at the bottom of that link, I drilled down through to another link which brought me to an article, that article had a zip attached and that link was dead, but I found another article containing the same project files so I linked to that article. – mhand Jun 18 '18 at 16:14