• Status: Solved
• Priority: Medium
• Security: Public
• Views: 509

# 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
2 Solutions

Commented:
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

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

Database / 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

Commented:
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

Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.