Solved

SQL: Factorial:: large numbers

Posted on 2013-06-17
5
480 Views
Last Modified: 2013-06-18
Hello team,
A non-recursive method in below will give me what I need, however, I would like to have a larger number than 38! and I know that either numeric or decimal can handle +- 38.  
Is there a way to use one of the 2 mentioned data types and use all the 72, not using the negative range?
(see attached)

Any assistance will be appreciated.
thx
factorial.png
0
Comment
Question by:John Esraelo
5 Comments
 
LVL 16

Accepted Solution

by:
DcpKing earned 100 total points
ID: 39254861
float
      

- 1.79E+308 to -2.23E-308, 0 and 2.23E-308 to 1.79E+308

(ref: http://msdn.microsoft.com/en-us/library/ms173773.aspx)

hth

Mike
0
 
LVL 16

Assisted Solution

by:Surendra Nath
Surendra Nath earned 400 total points
ID: 39254866
by using float one will loose the precission, i.e. in this case he will loose the last few digits....

I believe there is no data in sql server that will natively support this huge data, if there is one .NET you can use the SQL CLR functionality to get it loaded into SQL.
0
 

Author Closing Comment

by:John Esraelo
ID: 39254898
I am aware of all the data types but appreciate your responses.
I might start looking into some calculations in other bases, such as hex or something.. then convert the result to a character string.
0
 
LVL 16

Expert Comment

by:DcpKing
ID: 39255964
I think that if you are working with integers you might try converting all your numbers into right-justified, left-zero-filled varchars and then writing CLR functions in C# for adding, dividing, subtracting and multiplying. You might also search for articles on ASCII arithmetic and BCD.

Good luck!


Mike
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 39256466
This closed, but the number space of factorials is so small that you could just pre-compute them (or look them up) and store them in a table as strings.
Here they all are from 1 to 256
http://membres.multimania.fr/rsirdey/facttabl.htm
Just put those in the database and look them up. Don't bother doing all the math yourself.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how the fundamental information of how to create a table.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now