﻿{"id":904,"date":"2012-11-13T16:09:12","date_gmt":"2012-11-13T07:09:12","guid":{"rendered":"http:\/\/fujiitoshiki.com\/improvesociety\/?p=904"},"modified":"2014-07-31T13:36:49","modified_gmt":"2014-07-31T04:36:49","slug":"stored-procedure-to-calculate-factorial-with-natural-logarithm","status":"publish","type":"post","link":"https:\/\/www.fujiitoshiki.com\/improvesociety\/?p=904","title":{"rendered":"Stored procedure to calculate factorial with natural logarithm"},"content":{"rendered":"<div class=\"theContentWrap-ccc\"><p> <a href=\"\/\/rnk.mitelog.jp\/oyaji\/2012\/06\/sql-servervbnet-2955.html\" target=\"_blank\">This site<\/a> has shown stored procedure and function to calculate factorial with SQL. Although the logic is so simple as extracting one from previous argument and multiplying to it, it requires high cost of computing power. Therefore, the maximum of argument is restricted to so relatively small integer. In this article, you can calculate factorial with converting argument to natural logarithm, adding them and re-converting it to power of e, the base of natural logarithm. <\/p>\n<pre class=\"lang:tsql decode:true \" >\r\nCREATE PROCEDURE [dbo].[LOG_FACT]\r\n    @SrcNumber    FLOAT\r\nAS\r\nBEGIN\r\n    DECLARE\t@DesNumber    FLOAT\r\n    SET @DesNumber = LOG(1)\r\n    WHILE @SrcNumber > 0\r\n    BEGIN\r\n        SET @DesNumber = @DesNumber + LOG(@SrcNumber)\r\n        SET @SrcNumber = @SrcNumber - 1\r\n    END\r\n    SELECT\tEXP(@DesNumber)\r\nEND\r\n<\/pre>\n<p> Maximum of argument is 170. <\/p>\n<pre class=\"lang:tsql decode:true \" >\r\nEXEC LOG_FACT 170;\r\n7.25741561530971E+306\r\n<\/pre>\n<p><iframe style=\"width:120px;height:240px;\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" frameborder=\"0\" src=\"\/\/ws-na.amazon-adsystem.com\/widgets\/q?ServiceVersion=20070822&#038;OneJS=1&#038;Operation=GetAdHtml&#038;MarketPlace=US&#038;source=ss&#038;ref=ss_til&#038;ad_type=product_link&#038;tracking_id=improsocie-20&#038;marketplace=amazon&#038;region=US&#038;placement=0123820227&#038;asins=0123820227&#038;linkId=LXJBROSN54NZGFQG&#038;show_border=true&#038;link_opens_in_new_window=true\"><br \/>\n<\/iframe><iframe style=\"width:120px;height:240px;\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" frameborder=\"0\" src=\"\/\/ws-na.amazon-adsystem.com\/widgets\/q?ServiceVersion=20070822&#038;OneJS=1&#038;Operation=GetAdHtml&#038;MarketPlace=US&#038;source=ss&#038;ref=ss_til&#038;ad_type=product_link&#038;tracking_id=improsocie-20&#038;marketplace=amazon&#038;region=US&#038;placement=B00JI50L0M&#038;asins=B00JI50L0M&#038;linkId=TBXDLJXWCL2FZME3&#038;show_border=true&#038;link_opens_in_new_window=true\"><br \/>\n<\/iframe><\/p>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>This site has shown stored procedure and function to calculate factorial with SQL. Although the logic is so si &hellip; <a href=\"https:\/\/www.fujiitoshiki.com\/improvesociety\/?p=904\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Stored procedure to calculate factorial with natural logarithm&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":6024,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-904","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-database"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=\/wp\/v2\/posts\/904","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=904"}],"version-history":[{"count":16,"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=\/wp\/v2\/posts\/904\/revisions"}],"predecessor-version":[{"id":5943,"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=\/wp\/v2\/posts\/904\/revisions\/5943"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=\/wp\/v2\/media\/6024"}],"wp:attachment":[{"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=904"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=904"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=904"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}