BigInteger Square Root in F#(www.codeproject.com)

submitted by rcashrcash(4149) 7 months, 14 days ago

.NET does not provide an integer square root function for the BigInteger type in F#. In this article the author has built a square root function that takes a BigInteger and returns a BigInteger. Read entire article to see the code.

5 comments |category: |Views: 29

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:
Comments:

posted by dpetersondpeterson(4397) 7 months, 14 days ago 0

Not sure when I would ever need that in the type of work that I do normally, but it's very cool nonetheless to see the entire solution worked out in F#. Seems like math is very natural in F#.

Reply

posted by bradygasterbradygaster(4897) replied to dpetersondpeterson(4397), 7 months, 14 days ago 0

Indeed. The more F# articles I read the more I want to investigate it. I do wish there were more real-world, LOB-style examples of how to use F# out there but I guess everything comes in time. :)

Reply

posted by dpetersondpeterson(4397) replied to bradygasterbradygaster(4897), 7 months, 14 days ago 0

I could see it being useful in LOB apps like stock apps or other apps with lots of charting/math. Not sure if it does math any faster as it's still all on the CLR, but I suppose it's possible the F# compiler is better at math. Regardless, math is definitely more natural in F#.

Reply

posted by NoldorinNoldorin(829) replied to dpetersondpeterson(4397), 7 months, 13 days ago 0

I've seen pretty directly how F# (or more traditional functional languages) are favoured in particular in scientific research as well as financial research. The manner in which you can do data manipulation and implement mathematical algorithms seems to be much more amenable to the mathematician/statistician/scientist's mind, where Matlab commonly gets used. C/C++ will of course be also be used for performance-intesnive applications in some way, but F# is often good enough.

To be fair, I know a few folks who are keen enough on F# to use it as their primary (.NET) language. It certainly is innovative in that it really offers full support for O-O and functional programming, without compromising either significantly. The complexity of the code the compiler generates, and indeed the speed of the compiler itself may still be preventing wider adoption though. Personally, I still consider it to be a domain-specific language to some degree. While there's nothing stopping you from using it like C# in business applications now, the it's probably not the prettiest.

Reply

posted by NoldorinNoldorin(829) 7 months, 13 days ago 0

While this article is a good and unique introduction to functional programming, it should be noted that the algorithm itself (the application of the Newton-Raphson in this case) is not particularly efficient. The Wikipedia page <http://en.wikipedia.org/wiki/Methods_of_computing_square_roots> offers some better algorithms.

Reply

information Login or create an account to comment on this story