5

I need to get a hold of the ORIGINAL source code for System.Numerics.BigInteger with developer comments and sensible variable names. I know how to decompile assemblies and that is not the answer I'm looking for.

What I have tried:

  • Downloading the source code for both .NET 4 and 4.5 but BigInteger is not included for some reason.
  • Source stepping by following MS instructions but that did not work due to this issue with SP1 and I don't have the option of rolling back on my dev machine. Nor do I have access to another dev-capable machine.

I'm sure many of you have used source-stepping to debug and/or view BCL source code. If you have, please post the BigInteger and dependent code as an answer. If doing that crosses any legal boundaries, please let me know the same so I can jump at alternatives. If you do suggest alternatives, please include a concrete reason for doing so.

Community
  • 1
  • 1
Raheel Khan
  • 14,205
  • 13
  • 80
  • 168
  • 2
    Why is you actual need? What are you searching for? – SimpleVar Aug 25 '12 at 15:59
  • The source code for 'System.Numerics.BigInteger'. I've already spent days researching the debugging issue and the source is my last resort. I need to understand the internals of BigInteger for an urgent task. – Raheel Khan Aug 25 '12 at 16:01
  • You can throw ILSpy at `System.Numerics.dll`. Personally I avoid looking an MS's reference source or decompiled framework code, but if you don't care about that, decompiling is an easy solution. I always found decompiled .net code to be easy to read. – CodesInChaos Aug 25 '12 at 17:13
  • If it doesn't need to be MS's code, you can always look at mono's implementation, which is published under MIT X11. – CodesInChaos Aug 25 '12 at 17:13
  • The source for BigInteger (or the Numerics asssembly) seems to not be currently not available. As as been pointed out, maybe check out Mono's source. – Peter Ritchie Aug 25 '12 at 17:55
  • @PeterRitchie: Could you please point me to a reliable source that confirms the desired source as not available? Because if that is really the case, I need to completely re-weigh my options. This is for a commercial project under a deadline so if I cannot have access to this, I need to consider commercial alternatives. Thanks. – Raheel Khan Aug 25 '12 at 19:20
  • 3
    @RaheelKhan The only reliable source to what *is* available is http://referencesource.microsoft.com/netframework.aspx If you don't find it there, it's not currently available. Many other commercial software packages are successfully using .NET without having the entire commented source code. If you provide detail about what you need, maybe someone can help. There is a Reference Source forum here: http://social.msdn.microsoft.com/Forums/en-US/refsourceserver/threads?page=1 maybe that would be a better place to ask – Peter Ritchie Aug 25 '12 at 19:57
  • If it's OK to get the code by stepping through, what's wrong with using something like JustDecompile? – BlackWasp Aug 25 '12 at 19:57
  • check this: http://bcl.codeplex.com/releases/view/42782 – Nesim Razon Aug 25 '12 at 19:59
  • @PeterRitchie: I appreciate your comment and it does bring me one step closer to a decision. I will, of course, ask on that forum, but since time is limited, I was hoping someone who has already configured step-through for .NET 4 may have the source for BigInteger (even if it is for the beta release). – Raheel Khan Aug 25 '12 at 20:26
  • When I asked what you really need, I wasn't expecting you to answer "the source code of BigInteger" - that I already knew. I want to know your real problem, the thing that caused you to need looking at the source code, the basic problem. – SimpleVar Aug 26 '12 at 01:21
  • @YoryeNathan: I need to make some unsafe arithmetic optimizations to the code that can potentially reduce execution time of my algorithm by as much as 50%. While making these changes, I'd rather not rely on my interpretation of decompiled code. – Raheel Khan Aug 26 '12 at 01:25
  • Why won't you just write that class yourself, and test it's performance against the original BigInteger class? The general idea of BigInteger is a list of ints, with ints at lower index being more significant to the value. – SimpleVar Aug 26 '12 at 01:36
  • @YoryeNathan: This is for a production application and I am working on a deadline. Writing the class from scratch is not a risk I want to take and I would rather build upon the .NET implementation than other third-party ones. That is why I emphasized on not preferring alternative suggestions to the question. – Raheel Khan Aug 26 '12 at 01:39
  • I can't see how writing it your own counts as any risk, as long as you have good testing. The only issue might be the deadline - is it? – SimpleVar Aug 26 '12 at 01:44
  • @YoryeNathan: Yes, that is what I meant by risk. I know enough about arithmetic and programming concepts to know exactly what to optimize but do not have time to research the more advanced principals required for re-implementation. There are a lot of arithmetic shortcuts and bit hacks in there. Even if I did have time, why would I want to re-invent the wheel unless it was for a hobby project. – Raheel Khan Aug 26 '12 at 01:53
  • 2
    http://referencesource.microsoft.com/#System.Numerics/System/Numerics/BigInteger.cs,035eb7acfa6585a0 – ta.speot.is Jun 02 '15 at 05:40

2 Answers2

3

This has been asked before on MSDN BigInteger source code

Your not going to get it with code comments unless you have access to the private Micrsoft source and symbol servers.

The source stepping is your best bet. I too have experienced the problems you mention and found the RedGate source stepper (part of Reflector trial on a VM) does the trick.

An alternate would be to use a 3rd party if you dont have time to write your own: http://www.codeproject.com/Articles/2728/C-BigInteger-Class

UPDATE:

Heinzi
  • 167,459
  • 57
  • 363
  • 519
Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
  • Thank you. Your answer and Peter Ritchie's comment were the only two responses that addressed the actual question. I'll look into RedGate. – Raheel Khan Aug 26 '12 at 02:47
  • 1
    http://referencesource.microsoft.com/#System.Numerics/System/Numerics/BigInteger.cs – Qwertiy Jun 26 '17 at 11:13
  • The source code for the .NET Core runtime (and .NET 5, .NET 6, etc) is available with comments on GitHub: https://github.com/dotnet/runtime/blob/main/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs – Bip901 Feb 22 '22 at 07:53
1

This is the BigInteger source code according to JustDecompiler, given the framework's dll of BigInteger: http://pastebin.com/hFXJ7m8p

SimpleVar
  • 14,044
  • 4
  • 38
  • 60
  • This is from a decompiler, which the asker pointed out is not sufficient. – Tim S. Aug 26 '12 at 02:26
  • But I don't see any reason to that, because it is after all the source code (only comments are omitted, and they aren't really necessary in this case) – SimpleVar Aug 26 '12 at 02:30
  • I don't agree with his requests either, but 'tis what he asked for... – Tim S. Aug 26 '12 at 02:35
  • Well, obviously, you can't actually get the source source-code unless you were one of the coders or have access to Microsoft computers or something like that... – SimpleVar Aug 26 '12 at 02:35
  • And that is the bottom line, [it isn't available](http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/8df4e47a-f8af-49eb-880a-beac2ab795c8) – Jeremy Thompson Aug 26 '12 at 02:37
  • From what he said, I understand that using the decompiled code should be as good as the original source code. It just sounds like he doesn't trust decompilers enough to use them for that case, for some reason... – SimpleVar Aug 26 '12 at 02:39