[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 504
  • Last Modified:

SQL: Factorial:: large numbers

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
John Esraelo
Asked:
John Esraelo
2 Solutions
 
DcpKingCommented:
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
 
Surendra NathCommented:
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
 
John EsraeloDatabase / SQL DeveloperAuthor Commented:
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
 
DcpKingCommented:
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
 
TommySzalapskiCommented:
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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now