numeric.out 105 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226
  1. --
  2. -- NUMERIC
  3. --
  4. CREATE TABLE num_data (id int4, val numeric(210,10));
  5. CREATE TABLE num_exp_add (id1 int4, id2 int4, expected numeric(210,10));
  6. CREATE TABLE num_exp_sub (id1 int4, id2 int4, expected numeric(210,10));
  7. CREATE TABLE num_exp_div (id1 int4, id2 int4, expected numeric(210,10));
  8. CREATE TABLE num_exp_mul (id1 int4, id2 int4, expected numeric(210,10));
  9. CREATE TABLE num_exp_sqrt (id int4, expected numeric(210,10));
  10. CREATE TABLE num_exp_ln (id int4, expected numeric(210,10));
  11. CREATE TABLE num_exp_log10 (id int4, expected numeric(210,10));
  12. CREATE TABLE num_exp_power_10_ln (id int4, expected numeric(210,10));
  13. CREATE TABLE num_result (id1 int4, id2 int4, result numeric(210,10));
  14. -- ******************************
  15. -- * The following EXPECTED results are computed by bc(1)
  16. -- * with a scale of 200
  17. -- ******************************
  18. BEGIN TRANSACTION;
  19. INSERT INTO num_exp_add VALUES (0,0,'0');
  20. INSERT INTO num_exp_sub VALUES (0,0,'0');
  21. INSERT INTO num_exp_mul VALUES (0,0,'0');
  22. INSERT INTO num_exp_div VALUES (0,0,'NaN');
  23. INSERT INTO num_exp_add VALUES (0,1,'0');
  24. INSERT INTO num_exp_sub VALUES (0,1,'0');
  25. INSERT INTO num_exp_mul VALUES (0,1,'0');
  26. INSERT INTO num_exp_div VALUES (0,1,'NaN');
  27. INSERT INTO num_exp_add VALUES (0,2,'-34338492.215397047');
  28. INSERT INTO num_exp_sub VALUES (0,2,'34338492.215397047');
  29. INSERT INTO num_exp_mul VALUES (0,2,'0');
  30. INSERT INTO num_exp_div VALUES (0,2,'0');
  31. INSERT INTO num_exp_add VALUES (0,3,'4.31');
  32. INSERT INTO num_exp_sub VALUES (0,3,'-4.31');
  33. INSERT INTO num_exp_mul VALUES (0,3,'0');
  34. INSERT INTO num_exp_div VALUES (0,3,'0');
  35. INSERT INTO num_exp_add VALUES (0,4,'7799461.4119');
  36. INSERT INTO num_exp_sub VALUES (0,4,'-7799461.4119');
  37. INSERT INTO num_exp_mul VALUES (0,4,'0');
  38. INSERT INTO num_exp_div VALUES (0,4,'0');
  39. INSERT INTO num_exp_add VALUES (0,5,'16397.038491');
  40. INSERT INTO num_exp_sub VALUES (0,5,'-16397.038491');
  41. INSERT INTO num_exp_mul VALUES (0,5,'0');
  42. INSERT INTO num_exp_div VALUES (0,5,'0');
  43. INSERT INTO num_exp_add VALUES (0,6,'93901.57763026');
  44. INSERT INTO num_exp_sub VALUES (0,6,'-93901.57763026');
  45. INSERT INTO num_exp_mul VALUES (0,6,'0');
  46. INSERT INTO num_exp_div VALUES (0,6,'0');
  47. INSERT INTO num_exp_add VALUES (0,7,'-83028485');
  48. INSERT INTO num_exp_sub VALUES (0,7,'83028485');
  49. INSERT INTO num_exp_mul VALUES (0,7,'0');
  50. INSERT INTO num_exp_div VALUES (0,7,'0');
  51. INSERT INTO num_exp_add VALUES (0,8,'74881');
  52. INSERT INTO num_exp_sub VALUES (0,8,'-74881');
  53. INSERT INTO num_exp_mul VALUES (0,8,'0');
  54. INSERT INTO num_exp_div VALUES (0,8,'0');
  55. INSERT INTO num_exp_add VALUES (0,9,'-24926804.045047420');
  56. INSERT INTO num_exp_sub VALUES (0,9,'24926804.045047420');
  57. INSERT INTO num_exp_mul VALUES (0,9,'0');
  58. INSERT INTO num_exp_div VALUES (0,9,'0');
  59. INSERT INTO num_exp_add VALUES (1,0,'0');
  60. INSERT INTO num_exp_sub VALUES (1,0,'0');
  61. INSERT INTO num_exp_mul VALUES (1,0,'0');
  62. INSERT INTO num_exp_div VALUES (1,0,'NaN');
  63. INSERT INTO num_exp_add VALUES (1,1,'0');
  64. INSERT INTO num_exp_sub VALUES (1,1,'0');
  65. INSERT INTO num_exp_mul VALUES (1,1,'0');
  66. INSERT INTO num_exp_div VALUES (1,1,'NaN');
  67. INSERT INTO num_exp_add VALUES (1,2,'-34338492.215397047');
  68. INSERT INTO num_exp_sub VALUES (1,2,'34338492.215397047');
  69. INSERT INTO num_exp_mul VALUES (1,2,'0');
  70. INSERT INTO num_exp_div VALUES (1,2,'0');
  71. INSERT INTO num_exp_add VALUES (1,3,'4.31');
  72. INSERT INTO num_exp_sub VALUES (1,3,'-4.31');
  73. INSERT INTO num_exp_mul VALUES (1,3,'0');
  74. INSERT INTO num_exp_div VALUES (1,3,'0');
  75. INSERT INTO num_exp_add VALUES (1,4,'7799461.4119');
  76. INSERT INTO num_exp_sub VALUES (1,4,'-7799461.4119');
  77. INSERT INTO num_exp_mul VALUES (1,4,'0');
  78. INSERT INTO num_exp_div VALUES (1,4,'0');
  79. INSERT INTO num_exp_add VALUES (1,5,'16397.038491');
  80. INSERT INTO num_exp_sub VALUES (1,5,'-16397.038491');
  81. INSERT INTO num_exp_mul VALUES (1,5,'0');
  82. INSERT INTO num_exp_div VALUES (1,5,'0');
  83. INSERT INTO num_exp_add VALUES (1,6,'93901.57763026');
  84. INSERT INTO num_exp_sub VALUES (1,6,'-93901.57763026');
  85. INSERT INTO num_exp_mul VALUES (1,6,'0');
  86. INSERT INTO num_exp_div VALUES (1,6,'0');
  87. INSERT INTO num_exp_add VALUES (1,7,'-83028485');
  88. INSERT INTO num_exp_sub VALUES (1,7,'83028485');
  89. INSERT INTO num_exp_mul VALUES (1,7,'0');
  90. INSERT INTO num_exp_div VALUES (1,7,'0');
  91. INSERT INTO num_exp_add VALUES (1,8,'74881');
  92. INSERT INTO num_exp_sub VALUES (1,8,'-74881');
  93. INSERT INTO num_exp_mul VALUES (1,8,'0');
  94. INSERT INTO num_exp_div VALUES (1,8,'0');
  95. INSERT INTO num_exp_add VALUES (1,9,'-24926804.045047420');
  96. INSERT INTO num_exp_sub VALUES (1,9,'24926804.045047420');
  97. INSERT INTO num_exp_mul VALUES (1,9,'0');
  98. INSERT INTO num_exp_div VALUES (1,9,'0');
  99. INSERT INTO num_exp_add VALUES (2,0,'-34338492.215397047');
  100. INSERT INTO num_exp_sub VALUES (2,0,'-34338492.215397047');
  101. INSERT INTO num_exp_mul VALUES (2,0,'0');
  102. INSERT INTO num_exp_div VALUES (2,0,'NaN');
  103. INSERT INTO num_exp_add VALUES (2,1,'-34338492.215397047');
  104. INSERT INTO num_exp_sub VALUES (2,1,'-34338492.215397047');
  105. INSERT INTO num_exp_mul VALUES (2,1,'0');
  106. INSERT INTO num_exp_div VALUES (2,1,'NaN');
  107. INSERT INTO num_exp_add VALUES (2,2,'-68676984.430794094');
  108. INSERT INTO num_exp_sub VALUES (2,2,'0');
  109. INSERT INTO num_exp_mul VALUES (2,2,'1179132047626883.596862135856320209');
  110. INSERT INTO num_exp_div VALUES (2,2,'1.00000000000000000000');
  111. INSERT INTO num_exp_add VALUES (2,3,'-34338487.905397047');
  112. INSERT INTO num_exp_sub VALUES (2,3,'-34338496.525397047');
  113. INSERT INTO num_exp_mul VALUES (2,3,'-147998901.44836127257');
  114. INSERT INTO num_exp_div VALUES (2,3,'-7967167.56737750510440835266');
  115. INSERT INTO num_exp_add VALUES (2,4,'-26539030.803497047');
  116. INSERT INTO num_exp_sub VALUES (2,4,'-42137953.627297047');
  117. INSERT INTO num_exp_mul VALUES (2,4,'-267821744976817.8111137106593');
  118. INSERT INTO num_exp_div VALUES (2,4,'-4.40267480046830116685');
  119. INSERT INTO num_exp_add VALUES (2,5,'-34322095.176906047');
  120. INSERT INTO num_exp_sub VALUES (2,5,'-34354889.253888047');
  121. INSERT INTO num_exp_mul VALUES (2,5,'-563049578578.769242506736077');
  122. INSERT INTO num_exp_div VALUES (2,5,'-2094.18866914563535496429');
  123. INSERT INTO num_exp_add VALUES (2,6,'-34244590.637766787');
  124. INSERT INTO num_exp_sub VALUES (2,6,'-34432393.793027307');
  125. INSERT INTO num_exp_mul VALUES (2,6,'-3224438592470.18449811926184222');
  126. INSERT INTO num_exp_div VALUES (2,6,'-365.68599891479766440940');
  127. INSERT INTO num_exp_add VALUES (2,7,'-117366977.215397047');
  128. INSERT INTO num_exp_sub VALUES (2,7,'48689992.784602953');
  129. INSERT INTO num_exp_mul VALUES (2,7,'2851072985828710.485883795');
  130. INSERT INTO num_exp_div VALUES (2,7,'.41357483778485235518');
  131. INSERT INTO num_exp_add VALUES (2,8,'-34263611.215397047');
  132. INSERT INTO num_exp_sub VALUES (2,8,'-34413373.215397047');
  133. INSERT INTO num_exp_mul VALUES (2,8,'-2571300635581.146276407');
  134. INSERT INTO num_exp_div VALUES (2,8,'-458.57416721727870888476');
  135. INSERT INTO num_exp_add VALUES (2,9,'-59265296.260444467');
  136. INSERT INTO num_exp_sub VALUES (2,9,'-9411688.170349627');
  137. INSERT INTO num_exp_mul VALUES (2,9,'855948866655588.453741509242968740');
  138. INSERT INTO num_exp_div VALUES (2,9,'1.37757299946438931811');
  139. INSERT INTO num_exp_add VALUES (3,0,'4.31');
  140. INSERT INTO num_exp_sub VALUES (3,0,'4.31');
  141. INSERT INTO num_exp_mul VALUES (3,0,'0');
  142. INSERT INTO num_exp_div VALUES (3,0,'NaN');
  143. INSERT INTO num_exp_add VALUES (3,1,'4.31');
  144. INSERT INTO num_exp_sub VALUES (3,1,'4.31');
  145. INSERT INTO num_exp_mul VALUES (3,1,'0');
  146. INSERT INTO num_exp_div VALUES (3,1,'NaN');
  147. INSERT INTO num_exp_add VALUES (3,2,'-34338487.905397047');
  148. INSERT INTO num_exp_sub VALUES (3,2,'34338496.525397047');
  149. INSERT INTO num_exp_mul VALUES (3,2,'-147998901.44836127257');
  150. INSERT INTO num_exp_div VALUES (3,2,'-.00000012551512084352');
  151. INSERT INTO num_exp_add VALUES (3,3,'8.62');
  152. INSERT INTO num_exp_sub VALUES (3,3,'0');
  153. INSERT INTO num_exp_mul VALUES (3,3,'18.5761');
  154. INSERT INTO num_exp_div VALUES (3,3,'1.00000000000000000000');
  155. INSERT INTO num_exp_add VALUES (3,4,'7799465.7219');
  156. INSERT INTO num_exp_sub VALUES (3,4,'-7799457.1019');
  157. INSERT INTO num_exp_mul VALUES (3,4,'33615678.685289');
  158. INSERT INTO num_exp_div VALUES (3,4,'.00000055260225961552');
  159. INSERT INTO num_exp_add VALUES (3,5,'16401.348491');
  160. INSERT INTO num_exp_sub VALUES (3,5,'-16392.728491');
  161. INSERT INTO num_exp_mul VALUES (3,5,'70671.23589621');
  162. INSERT INTO num_exp_div VALUES (3,5,'.00026285234387695504');
  163. INSERT INTO num_exp_add VALUES (3,6,'93905.88763026');
  164. INSERT INTO num_exp_sub VALUES (3,6,'-93897.26763026');
  165. INSERT INTO num_exp_mul VALUES (3,6,'404715.7995864206');
  166. INSERT INTO num_exp_div VALUES (3,6,'.00004589912234457595');
  167. INSERT INTO num_exp_add VALUES (3,7,'-83028480.69');
  168. INSERT INTO num_exp_sub VALUES (3,7,'83028489.31');
  169. INSERT INTO num_exp_mul VALUES (3,7,'-357852770.35');
  170. INSERT INTO num_exp_div VALUES (3,7,'-.00000005190989574240');
  171. INSERT INTO num_exp_add VALUES (3,8,'74885.31');
  172. INSERT INTO num_exp_sub VALUES (3,8,'-74876.69');
  173. INSERT INTO num_exp_mul VALUES (3,8,'322737.11');
  174. INSERT INTO num_exp_div VALUES (3,8,'.00005755799201399553');
  175. INSERT INTO num_exp_add VALUES (3,9,'-24926799.735047420');
  176. INSERT INTO num_exp_sub VALUES (3,9,'24926808.355047420');
  177. INSERT INTO num_exp_mul VALUES (3,9,'-107434525.43415438020');
  178. INSERT INTO num_exp_div VALUES (3,9,'-.00000017290624149854');
  179. INSERT INTO num_exp_add VALUES (4,0,'7799461.4119');
  180. INSERT INTO num_exp_sub VALUES (4,0,'7799461.4119');
  181. INSERT INTO num_exp_mul VALUES (4,0,'0');
  182. INSERT INTO num_exp_div VALUES (4,0,'NaN');
  183. INSERT INTO num_exp_add VALUES (4,1,'7799461.4119');
  184. INSERT INTO num_exp_sub VALUES (4,1,'7799461.4119');
  185. INSERT INTO num_exp_mul VALUES (4,1,'0');
  186. INSERT INTO num_exp_div VALUES (4,1,'NaN');
  187. INSERT INTO num_exp_add VALUES (4,2,'-26539030.803497047');
  188. INSERT INTO num_exp_sub VALUES (4,2,'42137953.627297047');
  189. INSERT INTO num_exp_mul VALUES (4,2,'-267821744976817.8111137106593');
  190. INSERT INTO num_exp_div VALUES (4,2,'-.22713465002993920385');
  191. INSERT INTO num_exp_add VALUES (4,3,'7799465.7219');
  192. INSERT INTO num_exp_sub VALUES (4,3,'7799457.1019');
  193. INSERT INTO num_exp_mul VALUES (4,3,'33615678.685289');
  194. INSERT INTO num_exp_div VALUES (4,3,'1809619.81714617169373549883');
  195. INSERT INTO num_exp_add VALUES (4,4,'15598922.8238');
  196. INSERT INTO num_exp_sub VALUES (4,4,'0');
  197. INSERT INTO num_exp_mul VALUES (4,4,'60831598315717.14146161');
  198. INSERT INTO num_exp_div VALUES (4,4,'1.00000000000000000000');
  199. INSERT INTO num_exp_add VALUES (4,5,'7815858.450391');
  200. INSERT INTO num_exp_sub VALUES (4,5,'7783064.373409');
  201. INSERT INTO num_exp_mul VALUES (4,5,'127888068979.9935054429');
  202. INSERT INTO num_exp_div VALUES (4,5,'475.66281046305802686061');
  203. INSERT INTO num_exp_add VALUES (4,6,'7893362.98953026');
  204. INSERT INTO num_exp_sub VALUES (4,6,'7705559.83426974');
  205. INSERT INTO num_exp_mul VALUES (4,6,'732381731243.745115764094');
  206. INSERT INTO num_exp_div VALUES (4,6,'83.05996138436129499606');
  207. INSERT INTO num_exp_add VALUES (4,7,'-75229023.5881');
  208. INSERT INTO num_exp_sub VALUES (4,7,'90827946.4119');
  209. INSERT INTO num_exp_mul VALUES (4,7,'-647577464846017.9715');
  210. INSERT INTO num_exp_div VALUES (4,7,'-.09393717604145131637');
  211. INSERT INTO num_exp_add VALUES (4,8,'7874342.4119');
  212. INSERT INTO num_exp_sub VALUES (4,8,'7724580.4119');
  213. INSERT INTO num_exp_mul VALUES (4,8,'584031469984.4839');
  214. INSERT INTO num_exp_div VALUES (4,8,'104.15808298366741897143');
  215. INSERT INTO num_exp_add VALUES (4,9,'-17127342.633147420');
  216. INSERT INTO num_exp_sub VALUES (4,9,'32726265.456947420');
  217. INSERT INTO num_exp_mul VALUES (4,9,'-194415646271340.1815956522980');
  218. INSERT INTO num_exp_div VALUES (4,9,'-.31289456112403769409');
  219. INSERT INTO num_exp_add VALUES (5,0,'16397.038491');
  220. INSERT INTO num_exp_sub VALUES (5,0,'16397.038491');
  221. INSERT INTO num_exp_mul VALUES (5,0,'0');
  222. INSERT INTO num_exp_div VALUES (5,0,'NaN');
  223. INSERT INTO num_exp_add VALUES (5,1,'16397.038491');
  224. INSERT INTO num_exp_sub VALUES (5,1,'16397.038491');
  225. INSERT INTO num_exp_mul VALUES (5,1,'0');
  226. INSERT INTO num_exp_div VALUES (5,1,'NaN');
  227. INSERT INTO num_exp_add VALUES (5,2,'-34322095.176906047');
  228. INSERT INTO num_exp_sub VALUES (5,2,'34354889.253888047');
  229. INSERT INTO num_exp_mul VALUES (5,2,'-563049578578.769242506736077');
  230. INSERT INTO num_exp_div VALUES (5,2,'-.00047751189505192446');
  231. INSERT INTO num_exp_add VALUES (5,3,'16401.348491');
  232. INSERT INTO num_exp_sub VALUES (5,3,'16392.728491');
  233. INSERT INTO num_exp_mul VALUES (5,3,'70671.23589621');
  234. INSERT INTO num_exp_div VALUES (5,3,'3804.41728329466357308584');
  235. INSERT INTO num_exp_add VALUES (5,4,'7815858.450391');
  236. INSERT INTO num_exp_sub VALUES (5,4,'-7783064.373409');
  237. INSERT INTO num_exp_mul VALUES (5,4,'127888068979.9935054429');
  238. INSERT INTO num_exp_div VALUES (5,4,'.00210232958726897192');
  239. INSERT INTO num_exp_add VALUES (5,5,'32794.076982');
  240. INSERT INTO num_exp_sub VALUES (5,5,'0');
  241. INSERT INTO num_exp_mul VALUES (5,5,'268862871.275335557081');
  242. INSERT INTO num_exp_div VALUES (5,5,'1.00000000000000000000');
  243. INSERT INTO num_exp_add VALUES (5,6,'110298.61612126');
  244. INSERT INTO num_exp_sub VALUES (5,6,'-77504.53913926');
  245. INSERT INTO num_exp_mul VALUES (5,6,'1539707782.76899778633766');
  246. INSERT INTO num_exp_div VALUES (5,6,'.17461941433576102689');
  247. INSERT INTO num_exp_add VALUES (5,7,'-83012087.961509');
  248. INSERT INTO num_exp_sub VALUES (5,7,'83044882.038491');
  249. INSERT INTO num_exp_mul VALUES (5,7,'-1361421264394.416135');
  250. INSERT INTO num_exp_div VALUES (5,7,'-.00019748690453643710');
  251. INSERT INTO num_exp_add VALUES (5,8,'91278.038491');
  252. INSERT INTO num_exp_sub VALUES (5,8,'-58483.961509');
  253. INSERT INTO num_exp_mul VALUES (5,8,'1227826639.244571');
  254. INSERT INTO num_exp_div VALUES (5,8,'.21897461960978085228');
  255. INSERT INTO num_exp_add VALUES (5,9,'-24910407.006556420');
  256. INSERT INTO num_exp_sub VALUES (5,9,'24943201.083538420');
  257. INSERT INTO num_exp_mul VALUES (5,9,'-408725765384.257043660243220');
  258. INSERT INTO num_exp_div VALUES (5,9,'-.00065780749354660427');
  259. INSERT INTO num_exp_add VALUES (6,0,'93901.57763026');
  260. INSERT INTO num_exp_sub VALUES (6,0,'93901.57763026');
  261. INSERT INTO num_exp_mul VALUES (6,0,'0');
  262. INSERT INTO num_exp_div VALUES (6,0,'NaN');
  263. INSERT INTO num_exp_add VALUES (6,1,'93901.57763026');
  264. INSERT INTO num_exp_sub VALUES (6,1,'93901.57763026');
  265. INSERT INTO num_exp_mul VALUES (6,1,'0');
  266. INSERT INTO num_exp_div VALUES (6,1,'NaN');
  267. INSERT INTO num_exp_add VALUES (6,2,'-34244590.637766787');
  268. INSERT INTO num_exp_sub VALUES (6,2,'34432393.793027307');
  269. INSERT INTO num_exp_mul VALUES (6,2,'-3224438592470.18449811926184222');
  270. INSERT INTO num_exp_div VALUES (6,2,'-.00273458651128995823');
  271. INSERT INTO num_exp_add VALUES (6,3,'93905.88763026');
  272. INSERT INTO num_exp_sub VALUES (6,3,'93897.26763026');
  273. INSERT INTO num_exp_mul VALUES (6,3,'404715.7995864206');
  274. INSERT INTO num_exp_div VALUES (6,3,'21786.90896293735498839907');
  275. INSERT INTO num_exp_add VALUES (6,4,'7893362.98953026');
  276. INSERT INTO num_exp_sub VALUES (6,4,'-7705559.83426974');
  277. INSERT INTO num_exp_mul VALUES (6,4,'732381731243.745115764094');
  278. INSERT INTO num_exp_div VALUES (6,4,'.01203949512295682469');
  279. INSERT INTO num_exp_add VALUES (6,5,'110298.61612126');
  280. INSERT INTO num_exp_sub VALUES (6,5,'77504.53913926');
  281. INSERT INTO num_exp_mul VALUES (6,5,'1539707782.76899778633766');
  282. INSERT INTO num_exp_div VALUES (6,5,'5.72674008674192359679');
  283. INSERT INTO num_exp_add VALUES (6,6,'187803.15526052');
  284. INSERT INTO num_exp_sub VALUES (6,6,'0');
  285. INSERT INTO num_exp_mul VALUES (6,6,'8817506281.4517452372676676');
  286. INSERT INTO num_exp_div VALUES (6,6,'1.00000000000000000000');
  287. INSERT INTO num_exp_add VALUES (6,7,'-82934583.42236974');
  288. INSERT INTO num_exp_sub VALUES (6,7,'83122386.57763026');
  289. INSERT INTO num_exp_mul VALUES (6,7,'-7796505729750.37795610');
  290. INSERT INTO num_exp_div VALUES (6,7,'-.00113095617281538980');
  291. INSERT INTO num_exp_add VALUES (6,8,'168782.57763026');
  292. INSERT INTO num_exp_sub VALUES (6,8,'19020.57763026');
  293. INSERT INTO num_exp_mul VALUES (6,8,'7031444034.53149906');
  294. INSERT INTO num_exp_div VALUES (6,8,'1.25401073209839612184');
  295. INSERT INTO num_exp_add VALUES (6,9,'-24832902.467417160');
  296. INSERT INTO num_exp_sub VALUES (6,9,'25020705.622677680');
  297. INSERT INTO num_exp_mul VALUES (6,9,'-2340666225110.29929521292692920');
  298. INSERT INTO num_exp_div VALUES (6,9,'-.00376709254265256789');
  299. INSERT INTO num_exp_add VALUES (7,0,'-83028485');
  300. INSERT INTO num_exp_sub VALUES (7,0,'-83028485');
  301. INSERT INTO num_exp_mul VALUES (7,0,'0');
  302. INSERT INTO num_exp_div VALUES (7,0,'NaN');
  303. INSERT INTO num_exp_add VALUES (7,1,'-83028485');
  304. INSERT INTO num_exp_sub VALUES (7,1,'-83028485');
  305. INSERT INTO num_exp_mul VALUES (7,1,'0');
  306. INSERT INTO num_exp_div VALUES (7,1,'NaN');
  307. INSERT INTO num_exp_add VALUES (7,2,'-117366977.215397047');
  308. INSERT INTO num_exp_sub VALUES (7,2,'-48689992.784602953');
  309. INSERT INTO num_exp_mul VALUES (7,2,'2851072985828710.485883795');
  310. INSERT INTO num_exp_div VALUES (7,2,'2.41794207151503385700');
  311. INSERT INTO num_exp_add VALUES (7,3,'-83028480.69');
  312. INSERT INTO num_exp_sub VALUES (7,3,'-83028489.31');
  313. INSERT INTO num_exp_mul VALUES (7,3,'-357852770.35');
  314. INSERT INTO num_exp_div VALUES (7,3,'-19264149.65197215777262180974');
  315. INSERT INTO num_exp_add VALUES (7,4,'-75229023.5881');
  316. INSERT INTO num_exp_sub VALUES (7,4,'-90827946.4119');
  317. INSERT INTO num_exp_mul VALUES (7,4,'-647577464846017.9715');
  318. INSERT INTO num_exp_div VALUES (7,4,'-10.64541262725136247686');
  319. INSERT INTO num_exp_add VALUES (7,5,'-83012087.961509');
  320. INSERT INTO num_exp_sub VALUES (7,5,'-83044882.038491');
  321. INSERT INTO num_exp_mul VALUES (7,5,'-1361421264394.416135');
  322. INSERT INTO num_exp_div VALUES (7,5,'-5063.62688881730941836574');
  323. INSERT INTO num_exp_add VALUES (7,6,'-82934583.42236974');
  324. INSERT INTO num_exp_sub VALUES (7,6,'-83122386.57763026');
  325. INSERT INTO num_exp_mul VALUES (7,6,'-7796505729750.37795610');
  326. INSERT INTO num_exp_div VALUES (7,6,'-884.20756174009028770294');
  327. INSERT INTO num_exp_add VALUES (7,7,'-166056970');
  328. INSERT INTO num_exp_sub VALUES (7,7,'0');
  329. INSERT INTO num_exp_mul VALUES (7,7,'6893729321395225');
  330. INSERT INTO num_exp_div VALUES (7,7,'1.00000000000000000000');
  331. INSERT INTO num_exp_add VALUES (7,8,'-82953604');
  332. INSERT INTO num_exp_sub VALUES (7,8,'-83103366');
  333. INSERT INTO num_exp_mul VALUES (7,8,'-6217255985285');
  334. INSERT INTO num_exp_div VALUES (7,8,'-1108.80577182462841041118');
  335. INSERT INTO num_exp_add VALUES (7,9,'-107955289.045047420');
  336. INSERT INTO num_exp_sub VALUES (7,9,'-58101680.954952580');
  337. INSERT INTO num_exp_mul VALUES (7,9,'2069634775752159.035758700');
  338. INSERT INTO num_exp_div VALUES (7,9,'3.33089171198810413382');
  339. INSERT INTO num_exp_add VALUES (8,0,'74881');
  340. INSERT INTO num_exp_sub VALUES (8,0,'74881');
  341. INSERT INTO num_exp_mul VALUES (8,0,'0');
  342. INSERT INTO num_exp_div VALUES (8,0,'NaN');
  343. INSERT INTO num_exp_add VALUES (8,1,'74881');
  344. INSERT INTO num_exp_sub VALUES (8,1,'74881');
  345. INSERT INTO num_exp_mul VALUES (8,1,'0');
  346. INSERT INTO num_exp_div VALUES (8,1,'NaN');
  347. INSERT INTO num_exp_add VALUES (8,2,'-34263611.215397047');
  348. INSERT INTO num_exp_sub VALUES (8,2,'34413373.215397047');
  349. INSERT INTO num_exp_mul VALUES (8,2,'-2571300635581.146276407');
  350. INSERT INTO num_exp_div VALUES (8,2,'-.00218067233500788615');
  351. INSERT INTO num_exp_add VALUES (8,3,'74885.31');
  352. INSERT INTO num_exp_sub VALUES (8,3,'74876.69');
  353. INSERT INTO num_exp_mul VALUES (8,3,'322737.11');
  354. INSERT INTO num_exp_div VALUES (8,3,'17373.78190255220417633410');
  355. INSERT INTO num_exp_add VALUES (8,4,'7874342.4119');
  356. INSERT INTO num_exp_sub VALUES (8,4,'-7724580.4119');
  357. INSERT INTO num_exp_mul VALUES (8,4,'584031469984.4839');
  358. INSERT INTO num_exp_div VALUES (8,4,'.00960079113741758956');
  359. INSERT INTO num_exp_add VALUES (8,5,'91278.038491');
  360. INSERT INTO num_exp_sub VALUES (8,5,'58483.961509');
  361. INSERT INTO num_exp_mul VALUES (8,5,'1227826639.244571');
  362. INSERT INTO num_exp_div VALUES (8,5,'4.56673929509287019456');
  363. INSERT INTO num_exp_add VALUES (8,6,'168782.57763026');
  364. INSERT INTO num_exp_sub VALUES (8,6,'-19020.57763026');
  365. INSERT INTO num_exp_mul VALUES (8,6,'7031444034.53149906');
  366. INSERT INTO num_exp_div VALUES (8,6,'.79744134113322314424');
  367. INSERT INTO num_exp_add VALUES (8,7,'-82953604');
  368. INSERT INTO num_exp_sub VALUES (8,7,'83103366');
  369. INSERT INTO num_exp_mul VALUES (8,7,'-6217255985285');
  370. INSERT INTO num_exp_div VALUES (8,7,'-.00090187120721280172');
  371. INSERT INTO num_exp_add VALUES (8,8,'149762');
  372. INSERT INTO num_exp_sub VALUES (8,8,'0');
  373. INSERT INTO num_exp_mul VALUES (8,8,'5607164161');
  374. INSERT INTO num_exp_div VALUES (8,8,'1.00000000000000000000');
  375. INSERT INTO num_exp_add VALUES (8,9,'-24851923.045047420');
  376. INSERT INTO num_exp_sub VALUES (8,9,'25001685.045047420');
  377. INSERT INTO num_exp_mul VALUES (8,9,'-1866544013697.195857020');
  378. INSERT INTO num_exp_div VALUES (8,9,'-.00300403532938582735');
  379. INSERT INTO num_exp_add VALUES (9,0,'-24926804.045047420');
  380. INSERT INTO num_exp_sub VALUES (9,0,'-24926804.045047420');
  381. INSERT INTO num_exp_mul VALUES (9,0,'0');
  382. INSERT INTO num_exp_div VALUES (9,0,'NaN');
  383. INSERT INTO num_exp_add VALUES (9,1,'-24926804.045047420');
  384. INSERT INTO num_exp_sub VALUES (9,1,'-24926804.045047420');
  385. INSERT INTO num_exp_mul VALUES (9,1,'0');
  386. INSERT INTO num_exp_div VALUES (9,1,'NaN');
  387. INSERT INTO num_exp_add VALUES (9,2,'-59265296.260444467');
  388. INSERT INTO num_exp_sub VALUES (9,2,'9411688.170349627');
  389. INSERT INTO num_exp_mul VALUES (9,2,'855948866655588.453741509242968740');
  390. INSERT INTO num_exp_div VALUES (9,2,'.72591434384152961526');
  391. INSERT INTO num_exp_add VALUES (9,3,'-24926799.735047420');
  392. INSERT INTO num_exp_sub VALUES (9,3,'-24926808.355047420');
  393. INSERT INTO num_exp_mul VALUES (9,3,'-107434525.43415438020');
  394. INSERT INTO num_exp_div VALUES (9,3,'-5783481.21694835730858468677');
  395. INSERT INTO num_exp_add VALUES (9,4,'-17127342.633147420');
  396. INSERT INTO num_exp_sub VALUES (9,4,'-32726265.456947420');
  397. INSERT INTO num_exp_mul VALUES (9,4,'-194415646271340.1815956522980');
  398. INSERT INTO num_exp_div VALUES (9,4,'-3.19596478892958416484');
  399. INSERT INTO num_exp_add VALUES (9,5,'-24910407.006556420');
  400. INSERT INTO num_exp_sub VALUES (9,5,'-24943201.083538420');
  401. INSERT INTO num_exp_mul VALUES (9,5,'-408725765384.257043660243220');
  402. INSERT INTO num_exp_div VALUES (9,5,'-1520.20159364322004505807');
  403. INSERT INTO num_exp_add VALUES (9,6,'-24832902.467417160');
  404. INSERT INTO num_exp_sub VALUES (9,6,'-25020705.622677680');
  405. INSERT INTO num_exp_mul VALUES (9,6,'-2340666225110.29929521292692920');
  406. INSERT INTO num_exp_div VALUES (9,6,'-265.45671195426965751280');
  407. INSERT INTO num_exp_add VALUES (9,7,'-107955289.045047420');
  408. INSERT INTO num_exp_sub VALUES (9,7,'58101680.954952580');
  409. INSERT INTO num_exp_mul VALUES (9,7,'2069634775752159.035758700');
  410. INSERT INTO num_exp_div VALUES (9,7,'.30021990699995814689');
  411. INSERT INTO num_exp_add VALUES (9,8,'-24851923.045047420');
  412. INSERT INTO num_exp_sub VALUES (9,8,'-25001685.045047420');
  413. INSERT INTO num_exp_mul VALUES (9,8,'-1866544013697.195857020');
  414. INSERT INTO num_exp_div VALUES (9,8,'-332.88556569820675471748');
  415. INSERT INTO num_exp_add VALUES (9,9,'-49853608.090094840');
  416. INSERT INTO num_exp_sub VALUES (9,9,'0');
  417. INSERT INTO num_exp_mul VALUES (9,9,'621345559900192.420120630048656400');
  418. INSERT INTO num_exp_div VALUES (9,9,'1.00000000000000000000');
  419. COMMIT TRANSACTION;
  420. BEGIN TRANSACTION;
  421. INSERT INTO num_exp_sqrt VALUES (0,'0');
  422. INSERT INTO num_exp_sqrt VALUES (1,'0');
  423. INSERT INTO num_exp_sqrt VALUES (2,'5859.90547836712524903505');
  424. INSERT INTO num_exp_sqrt VALUES (3,'2.07605394920266944396');
  425. INSERT INTO num_exp_sqrt VALUES (4,'2792.75158435189147418923');
  426. INSERT INTO num_exp_sqrt VALUES (5,'128.05092147657509145473');
  427. INSERT INTO num_exp_sqrt VALUES (6,'306.43364311096782703406');
  428. INSERT INTO num_exp_sqrt VALUES (7,'9111.99676251039939975230');
  429. INSERT INTO num_exp_sqrt VALUES (8,'273.64392922189960397542');
  430. INSERT INTO num_exp_sqrt VALUES (9,'4992.67503899937593364766');
  431. COMMIT TRANSACTION;
  432. BEGIN TRANSACTION;
  433. INSERT INTO num_exp_ln VALUES (0,'NaN');
  434. INSERT INTO num_exp_ln VALUES (1,'NaN');
  435. INSERT INTO num_exp_ln VALUES (2,'17.35177750493897715514');
  436. INSERT INTO num_exp_ln VALUES (3,'1.46093790411565641971');
  437. INSERT INTO num_exp_ln VALUES (4,'15.86956523951936572464');
  438. INSERT INTO num_exp_ln VALUES (5,'9.70485601768871834038');
  439. INSERT INTO num_exp_ln VALUES (6,'11.45000246622944403127');
  440. INSERT INTO num_exp_ln VALUES (7,'18.23469429965478772991');
  441. INSERT INTO num_exp_ln VALUES (8,'11.22365546576315513668');
  442. INSERT INTO num_exp_ln VALUES (9,'17.03145425013166006962');
  443. COMMIT TRANSACTION;
  444. BEGIN TRANSACTION;
  445. INSERT INTO num_exp_log10 VALUES (0,'NaN');
  446. INSERT INTO num_exp_log10 VALUES (1,'NaN');
  447. INSERT INTO num_exp_log10 VALUES (2,'7.53578122160797276459');
  448. INSERT INTO num_exp_log10 VALUES (3,'.63447727016073160075');
  449. INSERT INTO num_exp_log10 VALUES (4,'6.89206461372691743345');
  450. INSERT INTO num_exp_log10 VALUES (5,'4.21476541614777768626');
  451. INSERT INTO num_exp_log10 VALUES (6,'4.97267288886207207671');
  452. INSERT INTO num_exp_log10 VALUES (7,'7.91922711353275546914');
  453. INSERT INTO num_exp_log10 VALUES (8,'4.87437163556421004138');
  454. INSERT INTO num_exp_log10 VALUES (9,'7.39666659961986567059');
  455. COMMIT TRANSACTION;
  456. BEGIN TRANSACTION;
  457. INSERT INTO num_exp_power_10_ln VALUES (0,'NaN');
  458. INSERT INTO num_exp_power_10_ln VALUES (1,'NaN');
  459. INSERT INTO num_exp_power_10_ln VALUES (2,'224790267919917955.13261618583642653184');
  460. INSERT INTO num_exp_power_10_ln VALUES (3,'28.90266599445155957393');
  461. INSERT INTO num_exp_power_10_ln VALUES (4,'7405685069594999.07733999469386277636');
  462. INSERT INTO num_exp_power_10_ln VALUES (5,'5068226527.32127265408584640098');
  463. INSERT INTO num_exp_power_10_ln VALUES (6,'281839893606.99372343357047819067');
  464. INSERT INTO num_exp_power_10_ln VALUES (7,'1716699575118597095.42330819910640247627');
  465. INSERT INTO num_exp_power_10_ln VALUES (8,'167361463828.07491320069016125952');
  466. INSERT INTO num_exp_power_10_ln VALUES (9,'107511333880052007.04141124673540337457');
  467. COMMIT TRANSACTION;
  468. BEGIN TRANSACTION;
  469. INSERT INTO num_data VALUES (0, '0');
  470. INSERT INTO num_data VALUES (1, '0');
  471. INSERT INTO num_data VALUES (2, '-34338492.215397047');
  472. INSERT INTO num_data VALUES (3, '4.31');
  473. INSERT INTO num_data VALUES (4, '7799461.4119');
  474. INSERT INTO num_data VALUES (5, '16397.038491');
  475. INSERT INTO num_data VALUES (6, '93901.57763026');
  476. INSERT INTO num_data VALUES (7, '-83028485');
  477. INSERT INTO num_data VALUES (8, '74881');
  478. INSERT INTO num_data VALUES (9, '-24926804.045047420');
  479. COMMIT TRANSACTION;
  480. -- ******************************
  481. -- * Create indices for faster checks
  482. -- ******************************
  483. CREATE UNIQUE INDEX num_exp_add_idx ON num_exp_add (id1, id2);
  484. CREATE UNIQUE INDEX num_exp_sub_idx ON num_exp_sub (id1, id2);
  485. CREATE UNIQUE INDEX num_exp_div_idx ON num_exp_div (id1, id2);
  486. CREATE UNIQUE INDEX num_exp_mul_idx ON num_exp_mul (id1, id2);
  487. CREATE UNIQUE INDEX num_exp_sqrt_idx ON num_exp_sqrt (id);
  488. CREATE UNIQUE INDEX num_exp_ln_idx ON num_exp_ln (id);
  489. CREATE UNIQUE INDEX num_exp_log10_idx ON num_exp_log10 (id);
  490. CREATE UNIQUE INDEX num_exp_power_10_ln_idx ON num_exp_power_10_ln (id);
  491. VACUUM ANALYZE num_exp_add;
  492. VACUUM ANALYZE num_exp_sub;
  493. VACUUM ANALYZE num_exp_div;
  494. VACUUM ANALYZE num_exp_mul;
  495. VACUUM ANALYZE num_exp_sqrt;
  496. VACUUM ANALYZE num_exp_ln;
  497. VACUUM ANALYZE num_exp_log10;
  498. VACUUM ANALYZE num_exp_power_10_ln;
  499. -- ******************************
  500. -- * Now check the behaviour of the NUMERIC type
  501. -- ******************************
  502. -- ******************************
  503. -- * Addition check
  504. -- ******************************
  505. DELETE FROM num_result;
  506. INSERT INTO num_result SELECT t1.id, t2.id, t1.val + t2.val
  507. FROM num_data t1, num_data t2;
  508. SELECT t1.id1, t1.id2, t1.result, t2.expected
  509. FROM num_result t1, num_exp_add t2
  510. WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
  511. AND t1.result != t2.expected;
  512. id1 | id2 | result | expected
  513. -----+-----+--------+----------
  514. (0 rows)
  515. DELETE FROM num_result;
  516. INSERT INTO num_result SELECT t1.id, t2.id, round(t1.val + t2.val, 10)
  517. FROM num_data t1, num_data t2;
  518. SELECT t1.id1, t1.id2, t1.result, round(t2.expected, 10) as expected
  519. FROM num_result t1, num_exp_add t2
  520. WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
  521. AND t1.result != round(t2.expected, 10);
  522. id1 | id2 | result | expected
  523. -----+-----+--------+----------
  524. (0 rows)
  525. -- ******************************
  526. -- * Subtraction check
  527. -- ******************************
  528. DELETE FROM num_result;
  529. INSERT INTO num_result SELECT t1.id, t2.id, t1.val - t2.val
  530. FROM num_data t1, num_data t2;
  531. SELECT t1.id1, t1.id2, t1.result, t2.expected
  532. FROM num_result t1, num_exp_sub t2
  533. WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
  534. AND t1.result != t2.expected;
  535. id1 | id2 | result | expected
  536. -----+-----+--------+----------
  537. (0 rows)
  538. DELETE FROM num_result;
  539. INSERT INTO num_result SELECT t1.id, t2.id, round(t1.val - t2.val, 40)
  540. FROM num_data t1, num_data t2;
  541. SELECT t1.id1, t1.id2, t1.result, round(t2.expected, 40)
  542. FROM num_result t1, num_exp_sub t2
  543. WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
  544. AND t1.result != round(t2.expected, 40);
  545. id1 | id2 | result | round
  546. -----+-----+--------+-------
  547. (0 rows)
  548. -- ******************************
  549. -- * Multiply check
  550. -- ******************************
  551. DELETE FROM num_result;
  552. INSERT INTO num_result SELECT t1.id, t2.id, t1.val * t2.val
  553. FROM num_data t1, num_data t2;
  554. SELECT t1.id1, t1.id2, t1.result, t2.expected
  555. FROM num_result t1, num_exp_mul t2
  556. WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
  557. AND t1.result != t2.expected;
  558. id1 | id2 | result | expected
  559. -----+-----+--------+----------
  560. (0 rows)
  561. DELETE FROM num_result;
  562. INSERT INTO num_result SELECT t1.id, t2.id, round(t1.val * t2.val, 30)
  563. FROM num_data t1, num_data t2;
  564. SELECT t1.id1, t1.id2, t1.result, round(t2.expected, 30) as expected
  565. FROM num_result t1, num_exp_mul t2
  566. WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
  567. AND t1.result != round(t2.expected, 30);
  568. id1 | id2 | result | expected
  569. -----+-----+--------+----------
  570. (0 rows)
  571. -- ******************************
  572. -- * Division check
  573. -- ******************************
  574. DELETE FROM num_result;
  575. INSERT INTO num_result SELECT t1.id, t2.id, t1.val / t2.val
  576. FROM num_data t1, num_data t2
  577. WHERE t2.val != '0.0';
  578. SELECT t1.id1, t1.id2, t1.result, t2.expected
  579. FROM num_result t1, num_exp_div t2
  580. WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
  581. AND t1.result != t2.expected;
  582. id1 | id2 | result | expected
  583. -----+-----+--------+----------
  584. (0 rows)
  585. DELETE FROM num_result;
  586. INSERT INTO num_result SELECT t1.id, t2.id, round(t1.val / t2.val, 80)
  587. FROM num_data t1, num_data t2
  588. WHERE t2.val != '0.0';
  589. SELECT t1.id1, t1.id2, t1.result, round(t2.expected, 80) as expected
  590. FROM num_result t1, num_exp_div t2
  591. WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
  592. AND t1.result != round(t2.expected, 80);
  593. id1 | id2 | result | expected
  594. -----+-----+--------+----------
  595. (0 rows)
  596. -- ******************************
  597. -- * Square root check
  598. -- ******************************
  599. DELETE FROM num_result;
  600. INSERT INTO num_result SELECT id, 0, SQRT(ABS(val))
  601. FROM num_data;
  602. SELECT t1.id1, t1.result, t2.expected
  603. FROM num_result t1, num_exp_sqrt t2
  604. WHERE t1.id1 = t2.id
  605. AND t1.result != t2.expected;
  606. id1 | result | expected
  607. -----+--------+----------
  608. (0 rows)
  609. -- ******************************
  610. -- * Natural logarithm check
  611. -- ******************************
  612. DELETE FROM num_result;
  613. INSERT INTO num_result SELECT id, 0, LN(ABS(val))
  614. FROM num_data
  615. WHERE val != '0.0';
  616. SELECT t1.id1, t1.result, t2.expected
  617. FROM num_result t1, num_exp_ln t2
  618. WHERE t1.id1 = t2.id
  619. AND t1.result != t2.expected;
  620. id1 | result | expected
  621. -----+--------+----------
  622. (0 rows)
  623. -- ******************************
  624. -- * Logarithm base 10 check
  625. -- ******************************
  626. DELETE FROM num_result;
  627. INSERT INTO num_result SELECT id, 0, LOG(numeric '10', ABS(val))
  628. FROM num_data
  629. WHERE val != '0.0';
  630. SELECT t1.id1, t1.result, t2.expected
  631. FROM num_result t1, num_exp_log10 t2
  632. WHERE t1.id1 = t2.id
  633. AND t1.result != t2.expected;
  634. id1 | result | expected
  635. -----+--------+----------
  636. (0 rows)
  637. -- ******************************
  638. -- * POWER(10, LN(value)) check
  639. -- ******************************
  640. DELETE FROM num_result;
  641. INSERT INTO num_result SELECT id, 0, POWER(numeric '10', LN(ABS(round(val,200))))
  642. FROM num_data
  643. WHERE val != '0.0';
  644. SELECT t1.id1, t1.result, t2.expected
  645. FROM num_result t1, num_exp_power_10_ln t2
  646. WHERE t1.id1 = t2.id
  647. AND t1.result != t2.expected;
  648. id1 | result | expected
  649. -----+--------+----------
  650. (0 rows)
  651. -- ******************************
  652. -- * Check behavior with Inf and NaN inputs. It's easiest to handle these
  653. -- * separately from the num_data framework used above, because some input
  654. -- * combinations will throw errors.
  655. -- ******************************
  656. WITH v(x) AS
  657. (VALUES('0'::numeric),('1'),('-1'),('4.2'),('inf'),('-inf'),('nan'))
  658. SELECT x1, x2,
  659. x1 + x2 AS sum,
  660. x1 - x2 AS diff,
  661. x1 * x2 AS prod
  662. FROM v AS v1(x1), v AS v2(x2);
  663. x1 | x2 | sum | diff | prod
  664. -----------+-----------+-----------+-----------+-----------
  665. 0 | 0 | 0 | 0 | 0
  666. 0 | 1 | 1 | -1 | 0
  667. 0 | -1 | -1 | 1 | 0
  668. 0 | 4.2 | 4.2 | -4.2 | 0.0
  669. 0 | Infinity | Infinity | -Infinity | NaN
  670. 0 | -Infinity | -Infinity | Infinity | NaN
  671. 0 | NaN | NaN | NaN | NaN
  672. 1 | 0 | 1 | 1 | 0
  673. 1 | 1 | 2 | 0 | 1
  674. 1 | -1 | 0 | 2 | -1
  675. 1 | 4.2 | 5.2 | -3.2 | 4.2
  676. 1 | Infinity | Infinity | -Infinity | Infinity
  677. 1 | -Infinity | -Infinity | Infinity | -Infinity
  678. 1 | NaN | NaN | NaN | NaN
  679. -1 | 0 | -1 | -1 | 0
  680. -1 | 1 | 0 | -2 | -1
  681. -1 | -1 | -2 | 0 | 1
  682. -1 | 4.2 | 3.2 | -5.2 | -4.2
  683. -1 | Infinity | Infinity | -Infinity | -Infinity
  684. -1 | -Infinity | -Infinity | Infinity | Infinity
  685. -1 | NaN | NaN | NaN | NaN
  686. 4.2 | 0 | 4.2 | 4.2 | 0.0
  687. 4.2 | 1 | 5.2 | 3.2 | 4.2
  688. 4.2 | -1 | 3.2 | 5.2 | -4.2
  689. 4.2 | 4.2 | 8.4 | 0.0 | 17.64
  690. 4.2 | Infinity | Infinity | -Infinity | Infinity
  691. 4.2 | -Infinity | -Infinity | Infinity | -Infinity
  692. 4.2 | NaN | NaN | NaN | NaN
  693. Infinity | 0 | Infinity | Infinity | NaN
  694. Infinity | 1 | Infinity | Infinity | Infinity
  695. Infinity | -1 | Infinity | Infinity | -Infinity
  696. Infinity | 4.2 | Infinity | Infinity | Infinity
  697. Infinity | Infinity | Infinity | NaN | Infinity
  698. Infinity | -Infinity | NaN | Infinity | -Infinity
  699. Infinity | NaN | NaN | NaN | NaN
  700. -Infinity | 0 | -Infinity | -Infinity | NaN
  701. -Infinity | 1 | -Infinity | -Infinity | -Infinity
  702. -Infinity | -1 | -Infinity | -Infinity | Infinity
  703. -Infinity | 4.2 | -Infinity | -Infinity | -Infinity
  704. -Infinity | Infinity | NaN | -Infinity | -Infinity
  705. -Infinity | -Infinity | -Infinity | NaN | Infinity
  706. -Infinity | NaN | NaN | NaN | NaN
  707. NaN | 0 | NaN | NaN | NaN
  708. NaN | 1 | NaN | NaN | NaN
  709. NaN | -1 | NaN | NaN | NaN
  710. NaN | 4.2 | NaN | NaN | NaN
  711. NaN | Infinity | NaN | NaN | NaN
  712. NaN | -Infinity | NaN | NaN | NaN
  713. NaN | NaN | NaN | NaN | NaN
  714. (49 rows)
  715. WITH v(x) AS
  716. (VALUES('0'::numeric),('1'),('-1'),('4.2'),('inf'),('-inf'),('nan'))
  717. SELECT x1, x2,
  718. x1 / x2 AS quot,
  719. x1 % x2 AS mod,
  720. div(x1, x2) AS div
  721. FROM v AS v1(x1), v AS v2(x2) WHERE x2 != 0;
  722. x1 | x2 | quot | mod | div
  723. -----------+-----------+-------------------------+------+-----------
  724. 0 | 1 | 0.00000000000000000000 | 0 | 0
  725. 1 | 1 | 1.00000000000000000000 | 0 | 1
  726. -1 | 1 | -1.00000000000000000000 | 0 | -1
  727. 4.2 | 1 | 4.2000000000000000 | 0.2 | 4
  728. Infinity | 1 | Infinity | NaN | Infinity
  729. -Infinity | 1 | -Infinity | NaN | -Infinity
  730. NaN | 1 | NaN | NaN | NaN
  731. 0 | -1 | 0.00000000000000000000 | 0 | 0
  732. 1 | -1 | -1.00000000000000000000 | 0 | -1
  733. -1 | -1 | 1.00000000000000000000 | 0 | 1
  734. 4.2 | -1 | -4.2000000000000000 | 0.2 | -4
  735. Infinity | -1 | -Infinity | NaN | -Infinity
  736. -Infinity | -1 | Infinity | NaN | Infinity
  737. NaN | -1 | NaN | NaN | NaN
  738. 0 | 4.2 | 0.00000000000000000000 | 0.0 | 0
  739. 1 | 4.2 | 0.23809523809523809524 | 1.0 | 0
  740. -1 | 4.2 | -0.23809523809523809524 | -1.0 | 0
  741. 4.2 | 4.2 | 1.00000000000000000000 | 0.0 | 1
  742. Infinity | 4.2 | Infinity | NaN | Infinity
  743. -Infinity | 4.2 | -Infinity | NaN | -Infinity
  744. NaN | 4.2 | NaN | NaN | NaN
  745. 0 | Infinity | 0 | 0 | 0
  746. 1 | Infinity | 0 | 1 | 0
  747. -1 | Infinity | 0 | -1 | 0
  748. 4.2 | Infinity | 0 | 4.2 | 0
  749. Infinity | Infinity | NaN | NaN | NaN
  750. -Infinity | Infinity | NaN | NaN | NaN
  751. NaN | Infinity | NaN | NaN | NaN
  752. 0 | -Infinity | 0 | 0 | 0
  753. 1 | -Infinity | 0 | 1 | 0
  754. -1 | -Infinity | 0 | -1 | 0
  755. 4.2 | -Infinity | 0 | 4.2 | 0
  756. Infinity | -Infinity | NaN | NaN | NaN
  757. -Infinity | -Infinity | NaN | NaN | NaN
  758. NaN | -Infinity | NaN | NaN | NaN
  759. 0 | NaN | NaN | NaN | NaN
  760. 1 | NaN | NaN | NaN | NaN
  761. -1 | NaN | NaN | NaN | NaN
  762. 4.2 | NaN | NaN | NaN | NaN
  763. Infinity | NaN | NaN | NaN | NaN
  764. -Infinity | NaN | NaN | NaN | NaN
  765. NaN | NaN | NaN | NaN | NaN
  766. (42 rows)
  767. SELECT 'inf'::numeric / '0';
  768. ERROR: division by zero
  769. SELECT '-inf'::numeric / '0';
  770. ERROR: division by zero
  771. SELECT 'nan'::numeric / '0';
  772. ?column?
  773. ----------
  774. NaN
  775. (1 row)
  776. SELECT '0'::numeric / '0';
  777. ERROR: division by zero
  778. SELECT 'inf'::numeric % '0';
  779. ERROR: division by zero
  780. SELECT '-inf'::numeric % '0';
  781. ERROR: division by zero
  782. SELECT 'nan'::numeric % '0';
  783. ?column?
  784. ----------
  785. NaN
  786. (1 row)
  787. SELECT '0'::numeric % '0';
  788. ERROR: division by zero
  789. SELECT div('inf'::numeric, '0');
  790. ERROR: division by zero
  791. SELECT div('-inf'::numeric, '0');
  792. ERROR: division by zero
  793. SELECT div('nan'::numeric, '0');
  794. div
  795. -----
  796. NaN
  797. (1 row)
  798. SELECT div('0'::numeric, '0');
  799. ERROR: division by zero
  800. WITH v(x) AS
  801. (VALUES('0'::numeric),('1'),('-1'),('4.2'),('-7.777'),('inf'),('-inf'),('nan'))
  802. SELECT x, -x as minusx, abs(x), floor(x), ceil(x), sign(x), numeric_inc(x) as inc
  803. FROM v;
  804. x | minusx | abs | floor | ceil | sign | inc
  805. -----------+-----------+----------+-----------+-----------+------+-----------
  806. 0 | 0 | 0 | 0 | 0 | 0 | 1
  807. 1 | -1 | 1 | 1 | 1 | 1 | 2
  808. -1 | 1 | 1 | -1 | -1 | -1 | 0
  809. 4.2 | -4.2 | 4.2 | 4 | 5 | 1 | 5.2
  810. -7.777 | 7.777 | 7.777 | -8 | -7 | -1 | -6.777
  811. Infinity | -Infinity | Infinity | Infinity | Infinity | 1 | Infinity
  812. -Infinity | Infinity | Infinity | -Infinity | -Infinity | -1 | -Infinity
  813. NaN | NaN | NaN | NaN | NaN | NaN | NaN
  814. (8 rows)
  815. WITH v(x) AS
  816. (VALUES('0'::numeric),('1'),('-1'),('4.2'),('-7.777'),('inf'),('-inf'),('nan'))
  817. SELECT x, round(x), round(x,1) as round1, trunc(x), trunc(x,1) as trunc1
  818. FROM v;
  819. x | round | round1 | trunc | trunc1
  820. -----------+-----------+-----------+-----------+-----------
  821. 0 | 0 | 0.0 | 0 | 0.0
  822. 1 | 1 | 1.0 | 1 | 1.0
  823. -1 | -1 | -1.0 | -1 | -1.0
  824. 4.2 | 4 | 4.2 | 4 | 4.2
  825. -7.777 | -8 | -7.8 | -7 | -7.7
  826. Infinity | Infinity | Infinity | Infinity | Infinity
  827. -Infinity | -Infinity | -Infinity | -Infinity | -Infinity
  828. NaN | NaN | NaN | NaN | NaN
  829. (8 rows)
  830. -- the large values fall into the numeric abbreviation code's maximal classes
  831. WITH v(x) AS
  832. (VALUES('0'::numeric),('1'),('-1'),('4.2'),('-7.777'),('1e340'),('-1e340'),
  833. ('inf'),('-inf'),('nan'),
  834. ('inf'),('-inf'),('nan'))
  835. SELECT substring(x::text, 1, 32)
  836. FROM v ORDER BY x;
  837. substring
  838. ----------------------------------
  839. -Infinity
  840. -Infinity
  841. -1000000000000000000000000000000
  842. -7.777
  843. -1
  844. 0
  845. 1
  846. 4.2
  847. 10000000000000000000000000000000
  848. Infinity
  849. Infinity
  850. NaN
  851. NaN
  852. (13 rows)
  853. WITH v(x) AS
  854. (VALUES('0'::numeric),('1'),('4.2'),('inf'),('nan'))
  855. SELECT x, sqrt(x)
  856. FROM v;
  857. x | sqrt
  858. ----------+-------------------
  859. 0 | 0.000000000000000
  860. 1 | 1.000000000000000
  861. 4.2 | 2.049390153191920
  862. Infinity | Infinity
  863. NaN | NaN
  864. (5 rows)
  865. SELECT sqrt('-1'::numeric);
  866. ERROR: cannot take square root of a negative number
  867. SELECT sqrt('-inf'::numeric);
  868. ERROR: cannot take square root of a negative number
  869. WITH v(x) AS
  870. (VALUES('1'::numeric),('4.2'),('inf'),('nan'))
  871. SELECT x,
  872. log(x),
  873. log10(x),
  874. ln(x)
  875. FROM v;
  876. x | log | log10 | ln
  877. ----------+--------------------+--------------------+--------------------
  878. 1 | 0.0000000000000000 | 0.0000000000000000 | 0.0000000000000000
  879. 4.2 | 0.6232492903979005 | 0.6232492903979005 | 1.4350845252893226
  880. Infinity | Infinity | Infinity | Infinity
  881. NaN | NaN | NaN | NaN
  882. (4 rows)
  883. SELECT ln('0'::numeric);
  884. ERROR: cannot take logarithm of zero
  885. SELECT ln('-1'::numeric);
  886. ERROR: cannot take logarithm of a negative number
  887. SELECT ln('-inf'::numeric);
  888. ERROR: cannot take logarithm of a negative number
  889. WITH v(x) AS
  890. (VALUES('2'::numeric),('4.2'),('inf'),('nan'))
  891. SELECT x1, x2,
  892. log(x1, x2)
  893. FROM v AS v1(x1), v AS v2(x2);
  894. x1 | x2 | log
  895. ----------+----------+--------------------
  896. 2 | 2 | 1.0000000000000000
  897. 2 | 4.2 | 2.0703893278913979
  898. 2 | Infinity | Infinity
  899. 2 | NaN | NaN
  900. 4.2 | 2 | 0.4830009440873890
  901. 4.2 | 4.2 | 1.0000000000000000
  902. 4.2 | Infinity | Infinity
  903. 4.2 | NaN | NaN
  904. Infinity | 2 | 0
  905. Infinity | 4.2 | 0
  906. Infinity | Infinity | NaN
  907. Infinity | NaN | NaN
  908. NaN | 2 | NaN
  909. NaN | 4.2 | NaN
  910. NaN | Infinity | NaN
  911. NaN | NaN | NaN
  912. (16 rows)
  913. SELECT log('0'::numeric, '10');
  914. ERROR: cannot take logarithm of zero
  915. SELECT log('10'::numeric, '0');
  916. ERROR: cannot take logarithm of zero
  917. SELECT log('-inf'::numeric, '10');
  918. ERROR: cannot take logarithm of a negative number
  919. SELECT log('10'::numeric, '-inf');
  920. ERROR: cannot take logarithm of a negative number
  921. SELECT log('inf'::numeric, '0');
  922. ERROR: cannot take logarithm of zero
  923. SELECT log('inf'::numeric, '-inf');
  924. ERROR: cannot take logarithm of a negative number
  925. SELECT log('-inf'::numeric, 'inf');
  926. ERROR: cannot take logarithm of a negative number
  927. WITH v(x) AS
  928. (VALUES('0'::numeric),('1'),('2'),('4.2'),('inf'),('nan'))
  929. SELECT x1, x2,
  930. power(x1, x2)
  931. FROM v AS v1(x1), v AS v2(x2) WHERE x1 != 0 OR x2 >= 0;
  932. x1 | x2 | power
  933. ----------+----------+---------------------
  934. 0 | 0 | 1.0000000000000000
  935. 0 | 1 | 0.0000000000000000
  936. 0 | 2 | 0.0000000000000000
  937. 0 | 4.2 | 0.0000000000000000
  938. 0 | Infinity | 0
  939. 0 | NaN | NaN
  940. 1 | 0 | 1.0000000000000000
  941. 1 | 1 | 1.0000000000000000
  942. 1 | 2 | 1.0000000000000000
  943. 1 | 4.2 | 1.0000000000000000
  944. 1 | Infinity | 1
  945. 1 | NaN | 1
  946. 2 | 0 | 1.0000000000000000
  947. 2 | 1 | 2.0000000000000000
  948. 2 | 2 | 4.0000000000000000
  949. 2 | 4.2 | 18.379173679952560
  950. 2 | Infinity | Infinity
  951. 2 | NaN | NaN
  952. 4.2 | 0 | 1.0000000000000000
  953. 4.2 | 1 | 4.2000000000000000
  954. 4.2 | 2 | 17.6400000000000000
  955. 4.2 | 4.2 | 414.61691860129675
  956. 4.2 | Infinity | Infinity
  957. 4.2 | NaN | NaN
  958. Infinity | 0 | 1
  959. Infinity | 1 | Infinity
  960. Infinity | 2 | Infinity
  961. Infinity | 4.2 | Infinity
  962. Infinity | Infinity | Infinity
  963. Infinity | NaN | NaN
  964. NaN | 0 | 1
  965. NaN | 1 | NaN
  966. NaN | 2 | NaN
  967. NaN | 4.2 | NaN
  968. NaN | Infinity | NaN
  969. NaN | NaN | NaN
  970. (36 rows)
  971. SELECT power('0'::numeric, '-1');
  972. ERROR: zero raised to a negative power is undefined
  973. SELECT power('0'::numeric, '-inf');
  974. ERROR: zero raised to a negative power is undefined
  975. SELECT power('-1'::numeric, 'inf');
  976. power
  977. -------
  978. 1
  979. (1 row)
  980. SELECT power('-2'::numeric, '3');
  981. power
  982. ---------------------
  983. -8.0000000000000000
  984. (1 row)
  985. SELECT power('-2'::numeric, '3.3');
  986. ERROR: a negative number raised to a non-integer power yields a complex result
  987. SELECT power('-2'::numeric, '-1');
  988. power
  989. ---------------------
  990. -0.5000000000000000
  991. (1 row)
  992. SELECT power('-2'::numeric, '-1.5');
  993. ERROR: a negative number raised to a non-integer power yields a complex result
  994. SELECT power('-2'::numeric, 'inf');
  995. power
  996. ----------
  997. Infinity
  998. (1 row)
  999. SELECT power('-2'::numeric, '-inf');
  1000. power
  1001. -------
  1002. 0
  1003. (1 row)
  1004. SELECT power('inf'::numeric, '-2');
  1005. power
  1006. -------
  1007. 0
  1008. (1 row)
  1009. SELECT power('inf'::numeric, '-inf');
  1010. power
  1011. -------
  1012. 0
  1013. (1 row)
  1014. SELECT power('-inf'::numeric, '2');
  1015. power
  1016. ----------
  1017. Infinity
  1018. (1 row)
  1019. SELECT power('-inf'::numeric, '3');
  1020. power
  1021. -----------
  1022. -Infinity
  1023. (1 row)
  1024. SELECT power('-inf'::numeric, '4.5');
  1025. ERROR: a negative number raised to a non-integer power yields a complex result
  1026. SELECT power('-inf'::numeric, '-2');
  1027. power
  1028. -------
  1029. 0
  1030. (1 row)
  1031. SELECT power('-inf'::numeric, '-3');
  1032. power
  1033. -------
  1034. 0
  1035. (1 row)
  1036. SELECT power('-inf'::numeric, '0');
  1037. power
  1038. -------
  1039. 1
  1040. (1 row)
  1041. SELECT power('-inf'::numeric, 'inf');
  1042. power
  1043. ----------
  1044. Infinity
  1045. (1 row)
  1046. SELECT power('-inf'::numeric, '-inf');
  1047. power
  1048. -------
  1049. 0
  1050. (1 row)
  1051. -- ******************************
  1052. -- * miscellaneous checks for things that have been broken in the past...
  1053. -- ******************************
  1054. -- numeric AVG used to fail on some platforms
  1055. SELECT AVG(val) FROM num_data;
  1056. avg
  1057. ------------------------
  1058. -13430913.592242320700
  1059. (1 row)
  1060. SELECT MAX(val) FROM num_data;
  1061. max
  1062. --------------------
  1063. 7799461.4119000000
  1064. (1 row)
  1065. SELECT MIN(val) FROM num_data;
  1066. min
  1067. ----------------------
  1068. -83028485.0000000000
  1069. (1 row)
  1070. SELECT STDDEV(val) FROM num_data;
  1071. stddev
  1072. -------------------------------
  1073. 27791203.28758835329805617386
  1074. (1 row)
  1075. SELECT VARIANCE(val) FROM num_data;
  1076. variance
  1077. --------------------------------------
  1078. 772350980172061.69659105821915863601
  1079. (1 row)
  1080. -- Check for appropriate rounding and overflow
  1081. CREATE TABLE fract_only (id int, val numeric(4,4));
  1082. INSERT INTO fract_only VALUES (1, '0.0');
  1083. INSERT INTO fract_only VALUES (2, '0.1');
  1084. INSERT INTO fract_only VALUES (3, '1.0'); -- should fail
  1085. ERROR: numeric field overflow
  1086. DETAIL: A field with precision 4, scale 4 must round to an absolute value less than 1.
  1087. INSERT INTO fract_only VALUES (4, '-0.9999');
  1088. INSERT INTO fract_only VALUES (5, '0.99994');
  1089. INSERT INTO fract_only VALUES (6, '0.99995'); -- should fail
  1090. ERROR: numeric field overflow
  1091. DETAIL: A field with precision 4, scale 4 must round to an absolute value less than 1.
  1092. INSERT INTO fract_only VALUES (7, '0.00001');
  1093. INSERT INTO fract_only VALUES (8, '0.00017');
  1094. INSERT INTO fract_only VALUES (9, 'NaN');
  1095. INSERT INTO fract_only VALUES (10, 'Inf'); -- should fail
  1096. ERROR: numeric field overflow
  1097. DETAIL: A field with precision 4, scale 4 cannot hold an infinite value.
  1098. INSERT INTO fract_only VALUES (11, '-Inf'); -- should fail
  1099. ERROR: numeric field overflow
  1100. DETAIL: A field with precision 4, scale 4 cannot hold an infinite value.
  1101. SELECT * FROM fract_only;
  1102. id | val
  1103. ----+---------
  1104. 1 | 0.0000
  1105. 2 | 0.1000
  1106. 4 | -0.9999
  1107. 5 | 0.9999
  1108. 7 | 0.0000
  1109. 8 | 0.0002
  1110. 9 | NaN
  1111. (7 rows)
  1112. DROP TABLE fract_only;
  1113. -- Check conversion to integers
  1114. SELECT (-9223372036854775808.5)::int8; -- should fail
  1115. ERROR: bigint out of range
  1116. SELECT (-9223372036854775808.4)::int8; -- ok
  1117. int8
  1118. ----------------------
  1119. -9223372036854775808
  1120. (1 row)
  1121. SELECT 9223372036854775807.4::int8; -- ok
  1122. int8
  1123. ---------------------
  1124. 9223372036854775807
  1125. (1 row)
  1126. SELECT 9223372036854775807.5::int8; -- should fail
  1127. ERROR: bigint out of range
  1128. SELECT (-2147483648.5)::int4; -- should fail
  1129. ERROR: integer out of range
  1130. SELECT (-2147483648.4)::int4; -- ok
  1131. int4
  1132. -------------
  1133. -2147483648
  1134. (1 row)
  1135. SELECT 2147483647.4::int4; -- ok
  1136. int4
  1137. ------------
  1138. 2147483647
  1139. (1 row)
  1140. SELECT 2147483647.5::int4; -- should fail
  1141. ERROR: integer out of range
  1142. SELECT (-32768.5)::int2; -- should fail
  1143. ERROR: smallint out of range
  1144. SELECT (-32768.4)::int2; -- ok
  1145. int2
  1146. --------
  1147. -32768
  1148. (1 row)
  1149. SELECT 32767.4::int2; -- ok
  1150. int2
  1151. -------
  1152. 32767
  1153. (1 row)
  1154. SELECT 32767.5::int2; -- should fail
  1155. ERROR: smallint out of range
  1156. -- Check inf/nan conversion behavior
  1157. SELECT 'NaN'::float8::numeric;
  1158. numeric
  1159. ---------
  1160. NaN
  1161. (1 row)
  1162. SELECT 'Infinity'::float8::numeric;
  1163. numeric
  1164. ----------
  1165. Infinity
  1166. (1 row)
  1167. SELECT '-Infinity'::float8::numeric;
  1168. numeric
  1169. -----------
  1170. -Infinity
  1171. (1 row)
  1172. SELECT 'NaN'::numeric::float8;
  1173. float8
  1174. --------
  1175. NaN
  1176. (1 row)
  1177. SELECT 'Infinity'::numeric::float8;
  1178. float8
  1179. ----------
  1180. Infinity
  1181. (1 row)
  1182. SELECT '-Infinity'::numeric::float8;
  1183. float8
  1184. -----------
  1185. -Infinity
  1186. (1 row)
  1187. SELECT 'NaN'::float4::numeric;
  1188. numeric
  1189. ---------
  1190. NaN
  1191. (1 row)
  1192. SELECT 'Infinity'::float4::numeric;
  1193. numeric
  1194. ----------
  1195. Infinity
  1196. (1 row)
  1197. SELECT '-Infinity'::float4::numeric;
  1198. numeric
  1199. -----------
  1200. -Infinity
  1201. (1 row)
  1202. SELECT 'NaN'::numeric::float4;
  1203. float4
  1204. --------
  1205. NaN
  1206. (1 row)
  1207. SELECT 'Infinity'::numeric::float4;
  1208. float4
  1209. ----------
  1210. Infinity
  1211. (1 row)
  1212. SELECT '-Infinity'::numeric::float4;
  1213. float4
  1214. -----------
  1215. -Infinity
  1216. (1 row)
  1217. SELECT '42'::int2::numeric;
  1218. numeric
  1219. ---------
  1220. 42
  1221. (1 row)
  1222. SELECT 'NaN'::numeric::int2;
  1223. ERROR: cannot convert NaN to smallint
  1224. SELECT 'Infinity'::numeric::int2;
  1225. ERROR: cannot convert infinity to smallint
  1226. SELECT '-Infinity'::numeric::int2;
  1227. ERROR: cannot convert infinity to smallint
  1228. SELECT 'NaN'::numeric::int4;
  1229. ERROR: cannot convert NaN to integer
  1230. SELECT 'Infinity'::numeric::int4;
  1231. ERROR: cannot convert infinity to integer
  1232. SELECT '-Infinity'::numeric::int4;
  1233. ERROR: cannot convert infinity to integer
  1234. SELECT 'NaN'::numeric::int8;
  1235. ERROR: cannot convert NaN to bigint
  1236. SELECT 'Infinity'::numeric::int8;
  1237. ERROR: cannot convert infinity to bigint
  1238. SELECT '-Infinity'::numeric::int8;
  1239. ERROR: cannot convert infinity to bigint
  1240. -- Simple check that ceil(), floor(), and round() work correctly
  1241. CREATE TABLE ceil_floor_round (a numeric);
  1242. INSERT INTO ceil_floor_round VALUES ('-5.5');
  1243. INSERT INTO ceil_floor_round VALUES ('-5.499999');
  1244. INSERT INTO ceil_floor_round VALUES ('9.5');
  1245. INSERT INTO ceil_floor_round VALUES ('9.4999999');
  1246. INSERT INTO ceil_floor_round VALUES ('0.0');
  1247. INSERT INTO ceil_floor_round VALUES ('0.0000001');
  1248. INSERT INTO ceil_floor_round VALUES ('-0.000001');
  1249. SELECT a, ceil(a), ceiling(a), floor(a), round(a) FROM ceil_floor_round;
  1250. a | ceil | ceiling | floor | round
  1251. -----------+------+---------+-------+-------
  1252. -5.5 | -5 | -5 | -6 | -6
  1253. -5.499999 | -5 | -5 | -6 | -5
  1254. 9.5 | 10 | 10 | 9 | 10
  1255. 9.4999999 | 10 | 10 | 9 | 9
  1256. 0.0 | 0 | 0 | 0 | 0
  1257. 0.0000001 | 1 | 1 | 0 | 0
  1258. -0.000001 | 0 | 0 | -1 | 0
  1259. (7 rows)
  1260. DROP TABLE ceil_floor_round;
  1261. -- Check rounding, it should round ties away from zero.
  1262. SELECT i as pow,
  1263. round((-2.5 * 10 ^ i)::numeric, -i),
  1264. round((-1.5 * 10 ^ i)::numeric, -i),
  1265. round((-0.5 * 10 ^ i)::numeric, -i),
  1266. round((0.5 * 10 ^ i)::numeric, -i),
  1267. round((1.5 * 10 ^ i)::numeric, -i),
  1268. round((2.5 * 10 ^ i)::numeric, -i)
  1269. FROM generate_series(-5,5) AS t(i);
  1270. pow | round | round | round | round | round | round
  1271. -----+----------+----------+----------+---------+---------+---------
  1272. -5 | -0.00003 | -0.00002 | -0.00001 | 0.00001 | 0.00002 | 0.00003
  1273. -4 | -0.0003 | -0.0002 | -0.0001 | 0.0001 | 0.0002 | 0.0003
  1274. -3 | -0.003 | -0.002 | -0.001 | 0.001 | 0.002 | 0.003
  1275. -2 | -0.03 | -0.02 | -0.01 | 0.01 | 0.02 | 0.03
  1276. -1 | -0.3 | -0.2 | -0.1 | 0.1 | 0.2 | 0.3
  1277. 0 | -3 | -2 | -1 | 1 | 2 | 3
  1278. 1 | -30 | -20 | -10 | 10 | 20 | 30
  1279. 2 | -300 | -200 | -100 | 100 | 200 | 300
  1280. 3 | -3000 | -2000 | -1000 | 1000 | 2000 | 3000
  1281. 4 | -30000 | -20000 | -10000 | 10000 | 20000 | 30000
  1282. 5 | -300000 | -200000 | -100000 | 100000 | 200000 | 300000
  1283. (11 rows)
  1284. -- Testing for width_bucket(). For convenience, we test both the
  1285. -- numeric and float8 versions of the function in this file.
  1286. -- errors
  1287. SELECT width_bucket(5.0, 3.0, 4.0, 0);
  1288. ERROR: count must be greater than zero
  1289. SELECT width_bucket(5.0, 3.0, 4.0, -5);
  1290. ERROR: count must be greater than zero
  1291. SELECT width_bucket(3.5, 3.0, 3.0, 888);
  1292. ERROR: lower bound cannot equal upper bound
  1293. SELECT width_bucket(5.0::float8, 3.0::float8, 4.0::float8, 0);
  1294. ERROR: count must be greater than zero
  1295. SELECT width_bucket(5.0::float8, 3.0::float8, 4.0::float8, -5);
  1296. ERROR: count must be greater than zero
  1297. SELECT width_bucket(3.5::float8, 3.0::float8, 3.0::float8, 888);
  1298. ERROR: lower bound cannot equal upper bound
  1299. SELECT width_bucket('NaN', 3.0, 4.0, 888);
  1300. ERROR: operand, lower bound, and upper bound cannot be NaN
  1301. SELECT width_bucket(0::float8, 'NaN', 4.0::float8, 888);
  1302. ERROR: operand, lower bound, and upper bound cannot be NaN
  1303. SELECT width_bucket(2.0, 3.0, '-inf', 888);
  1304. ERROR: lower and upper bounds must be finite
  1305. SELECT width_bucket(0::float8, '-inf', 4.0::float8, 888);
  1306. ERROR: lower and upper bounds must be finite
  1307. -- normal operation
  1308. CREATE TABLE width_bucket_test (operand_num numeric, operand_f8 float8);
  1309. COPY width_bucket_test (operand_num) FROM stdin;
  1310. UPDATE width_bucket_test SET operand_f8 = operand_num::float8;
  1311. SELECT
  1312. operand_num,
  1313. width_bucket(operand_num, 0, 10, 5) AS wb_1,
  1314. width_bucket(operand_f8, 0, 10, 5) AS wb_1f,
  1315. width_bucket(operand_num, 10, 0, 5) AS wb_2,
  1316. width_bucket(operand_f8, 10, 0, 5) AS wb_2f,
  1317. width_bucket(operand_num, 2, 8, 4) AS wb_3,
  1318. width_bucket(operand_f8, 2, 8, 4) AS wb_3f,
  1319. width_bucket(operand_num, 5.0, 5.5, 20) AS wb_4,
  1320. width_bucket(operand_f8, 5.0, 5.5, 20) AS wb_4f,
  1321. width_bucket(operand_num, -25, 25, 10) AS wb_5,
  1322. width_bucket(operand_f8, -25, 25, 10) AS wb_5f
  1323. FROM width_bucket_test;
  1324. operand_num | wb_1 | wb_1f | wb_2 | wb_2f | wb_3 | wb_3f | wb_4 | wb_4f | wb_5 | wb_5f
  1325. ------------------+------+-------+------+-------+------+-------+------+-------+------+-------
  1326. -5.2 | 0 | 0 | 6 | 6 | 0 | 0 | 0 | 0 | 4 | 4
  1327. -0.0000000001 | 0 | 0 | 6 | 6 | 0 | 0 | 0 | 0 | 5 | 5
  1328. 0.000000000001 | 1 | 1 | 5 | 5 | 0 | 0 | 0 | 0 | 6 | 6
  1329. 1 | 1 | 1 | 5 | 5 | 0 | 0 | 0 | 0 | 6 | 6
  1330. 1.99999999999999 | 1 | 1 | 5 | 5 | 0 | 0 | 0 | 0 | 6 | 6
  1331. 2 | 2 | 2 | 5 | 5 | 1 | 1 | 0 | 0 | 6 | 6
  1332. 2.00000000000001 | 2 | 2 | 4 | 4 | 1 | 1 | 0 | 0 | 6 | 6
  1333. 3 | 2 | 2 | 4 | 4 | 1 | 1 | 0 | 0 | 6 | 6
  1334. 4 | 3 | 3 | 4 | 4 | 2 | 2 | 0 | 0 | 6 | 6
  1335. 4.5 | 3 | 3 | 3 | 3 | 2 | 2 | 0 | 0 | 6 | 6
  1336. 5 | 3 | 3 | 3 | 3 | 3 | 3 | 1 | 1 | 7 | 7
  1337. 5.5 | 3 | 3 | 3 | 3 | 3 | 3 | 21 | 21 | 7 | 7
  1338. 6 | 4 | 4 | 3 | 3 | 3 | 3 | 21 | 21 | 7 | 7
  1339. 7 | 4 | 4 | 2 | 2 | 4 | 4 | 21 | 21 | 7 | 7
  1340. 8 | 5 | 5 | 2 | 2 | 5 | 5 | 21 | 21 | 7 | 7
  1341. 9 | 5 | 5 | 1 | 1 | 5 | 5 | 21 | 21 | 7 | 7
  1342. 9.99999999999999 | 5 | 5 | 1 | 1 | 5 | 5 | 21 | 21 | 7 | 7
  1343. 10 | 6 | 6 | 1 | 1 | 5 | 5 | 21 | 21 | 8 | 8
  1344. 10.0000000000001 | 6 | 6 | 0 | 0 | 5 | 5 | 21 | 21 | 8 | 8
  1345. (19 rows)
  1346. -- Check positive and negative infinity: we require
  1347. -- finite bucket bounds, but allow an infinite operand
  1348. SELECT width_bucket(0.0::numeric, 'Infinity'::numeric, 5, 10); -- error
  1349. ERROR: lower and upper bounds must be finite
  1350. SELECT width_bucket(0.0::numeric, 5, '-Infinity'::numeric, 20); -- error
  1351. ERROR: lower and upper bounds must be finite
  1352. SELECT width_bucket('Infinity'::numeric, 1, 10, 10),
  1353. width_bucket('-Infinity'::numeric, 1, 10, 10);
  1354. width_bucket | width_bucket
  1355. --------------+--------------
  1356. 11 | 0
  1357. (1 row)
  1358. SELECT width_bucket(0.0::float8, 'Infinity'::float8, 5, 10); -- error
  1359. ERROR: lower and upper bounds must be finite
  1360. SELECT width_bucket(0.0::float8, 5, '-Infinity'::float8, 20); -- error
  1361. ERROR: lower and upper bounds must be finite
  1362. SELECT width_bucket('Infinity'::float8, 1, 10, 10),
  1363. width_bucket('-Infinity'::float8, 1, 10, 10);
  1364. width_bucket | width_bucket
  1365. --------------+--------------
  1366. 11 | 0
  1367. (1 row)
  1368. DROP TABLE width_bucket_test;
  1369. -- Simple test for roundoff error when results should be exact
  1370. SELECT x, width_bucket(x::float8, 10, 100, 9) as flt,
  1371. width_bucket(x::numeric, 10, 100, 9) as num
  1372. FROM generate_series(0, 110, 10) x;
  1373. x | flt | num
  1374. -----+-----+-----
  1375. 0 | 0 | 0
  1376. 10 | 1 | 1
  1377. 20 | 2 | 2
  1378. 30 | 3 | 3
  1379. 40 | 4 | 4
  1380. 50 | 5 | 5
  1381. 60 | 6 | 6
  1382. 70 | 7 | 7
  1383. 80 | 8 | 8
  1384. 90 | 9 | 9
  1385. 100 | 10 | 10
  1386. 110 | 10 | 10
  1387. (12 rows)
  1388. SELECT x, width_bucket(x::float8, 100, 10, 9) as flt,
  1389. width_bucket(x::numeric, 100, 10, 9) as num
  1390. FROM generate_series(0, 110, 10) x;
  1391. x | flt | num
  1392. -----+-----+-----
  1393. 0 | 10 | 10
  1394. 10 | 10 | 10
  1395. 20 | 9 | 9
  1396. 30 | 8 | 8
  1397. 40 | 7 | 7
  1398. 50 | 6 | 6
  1399. 60 | 5 | 5
  1400. 70 | 4 | 4
  1401. 80 | 3 | 3
  1402. 90 | 2 | 2
  1403. 100 | 1 | 1
  1404. 110 | 0 | 0
  1405. (12 rows)
  1406. --
  1407. -- TO_CHAR()
  1408. --
  1409. SELECT to_char(val, '9G999G999G999G999G999')
  1410. FROM num_data;
  1411. to_char
  1412. ------------------------
  1413. 0
  1414. 0
  1415. -34,338,492
  1416. 4
  1417. 7,799,461
  1418. 16,397
  1419. 93,902
  1420. -83,028,485
  1421. 74,881
  1422. -24,926,804
  1423. (10 rows)
  1424. SELECT to_char(val, '9G999G999G999G999G999D999G999G999G999G999')
  1425. FROM num_data;
  1426. to_char
  1427. --------------------------------------------
  1428. .000,000,000,000,000
  1429. .000,000,000,000,000
  1430. -34,338,492.215,397,047,000,000
  1431. 4.310,000,000,000,000
  1432. 7,799,461.411,900,000,000,000
  1433. 16,397.038,491,000,000,000
  1434. 93,901.577,630,260,000,000
  1435. -83,028,485.000,000,000,000,000
  1436. 74,881.000,000,000,000,000
  1437. -24,926,804.045,047,420,000,000
  1438. (10 rows)
  1439. SELECT to_char(val, '9999999999999999.999999999999999PR')
  1440. FROM num_data;
  1441. to_char
  1442. ------------------------------------
  1443. .000000000000000
  1444. .000000000000000
  1445. <34338492.215397047000000>
  1446. 4.310000000000000
  1447. 7799461.411900000000000
  1448. 16397.038491000000000
  1449. 93901.577630260000000
  1450. <83028485.000000000000000>
  1451. 74881.000000000000000
  1452. <24926804.045047420000000>
  1453. (10 rows)
  1454. SELECT to_char(val, '9999999999999999.999999999999999S')
  1455. FROM num_data;
  1456. to_char
  1457. -----------------------------------
  1458. .000000000000000+
  1459. .000000000000000+
  1460. 34338492.215397047000000-
  1461. 4.310000000000000+
  1462. 7799461.411900000000000+
  1463. 16397.038491000000000+
  1464. 93901.577630260000000+
  1465. 83028485.000000000000000-
  1466. 74881.000000000000000+
  1467. 24926804.045047420000000-
  1468. (10 rows)
  1469. SELECT to_char(val, 'MI9999999999999999.999999999999999') FROM num_data;
  1470. to_char
  1471. -----------------------------------
  1472. .000000000000000
  1473. .000000000000000
  1474. - 34338492.215397047000000
  1475. 4.310000000000000
  1476. 7799461.411900000000000
  1477. 16397.038491000000000
  1478. 93901.577630260000000
  1479. - 83028485.000000000000000
  1480. 74881.000000000000000
  1481. - 24926804.045047420000000
  1482. (10 rows)
  1483. SELECT to_char(val, 'FMS9999999999999999.999999999999999') FROM num_data;
  1484. to_char
  1485. ---------------------
  1486. +0.
  1487. +0.
  1488. -34338492.215397047
  1489. +4.31
  1490. +7799461.4119
  1491. +16397.038491
  1492. +93901.57763026
  1493. -83028485.
  1494. +74881.
  1495. -24926804.04504742
  1496. (10 rows)
  1497. SELECT to_char(val, 'FM9999999999999999.999999999999999THPR') FROM num_data;
  1498. to_char
  1499. ----------------------
  1500. 0.
  1501. 0.
  1502. <34338492.215397047>
  1503. 4.31
  1504. 7799461.4119
  1505. 16397.038491
  1506. 93901.57763026
  1507. <83028485.>
  1508. 74881.
  1509. <24926804.04504742>
  1510. (10 rows)
  1511. SELECT to_char(val, 'SG9999999999999999.999999999999999th') FROM num_data;
  1512. to_char
  1513. -----------------------------------
  1514. + .000000000000000
  1515. + .000000000000000
  1516. - 34338492.215397047000000
  1517. + 4.310000000000000
  1518. + 7799461.411900000000000
  1519. + 16397.038491000000000
  1520. + 93901.577630260000000
  1521. - 83028485.000000000000000
  1522. + 74881.000000000000000
  1523. - 24926804.045047420000000
  1524. (10 rows)
  1525. SELECT to_char(val, '0999999999999999.999999999999999') FROM num_data;
  1526. to_char
  1527. -----------------------------------
  1528. 0000000000000000.000000000000000
  1529. 0000000000000000.000000000000000
  1530. -0000000034338492.215397047000000
  1531. 0000000000000004.310000000000000
  1532. 0000000007799461.411900000000000
  1533. 0000000000016397.038491000000000
  1534. 0000000000093901.577630260000000
  1535. -0000000083028485.000000000000000
  1536. 0000000000074881.000000000000000
  1537. -0000000024926804.045047420000000
  1538. (10 rows)
  1539. SELECT to_char(val, 'S0999999999999999.999999999999999') FROM num_data;
  1540. to_char
  1541. -----------------------------------
  1542. +0000000000000000.000000000000000
  1543. +0000000000000000.000000000000000
  1544. -0000000034338492.215397047000000
  1545. +0000000000000004.310000000000000
  1546. +0000000007799461.411900000000000
  1547. +0000000000016397.038491000000000
  1548. +0000000000093901.577630260000000
  1549. -0000000083028485.000000000000000
  1550. +0000000000074881.000000000000000
  1551. -0000000024926804.045047420000000
  1552. (10 rows)
  1553. SELECT to_char(val, 'FM0999999999999999.999999999999999') FROM num_data;
  1554. to_char
  1555. -----------------------------
  1556. 0000000000000000.
  1557. 0000000000000000.
  1558. -0000000034338492.215397047
  1559. 0000000000000004.31
  1560. 0000000007799461.4119
  1561. 0000000000016397.038491
  1562. 0000000000093901.57763026
  1563. -0000000083028485.
  1564. 0000000000074881.
  1565. -0000000024926804.04504742
  1566. (10 rows)
  1567. SELECT to_char(val, 'FM9999999999999999.099999999999999') FROM num_data;
  1568. to_char
  1569. ---------------------
  1570. .0
  1571. .0
  1572. -34338492.215397047
  1573. 4.31
  1574. 7799461.4119
  1575. 16397.038491
  1576. 93901.57763026
  1577. -83028485.0
  1578. 74881.0
  1579. -24926804.04504742
  1580. (10 rows)
  1581. SELECT to_char(val, 'FM9999999999990999.990999999999999') FROM num_data;
  1582. to_char
  1583. ---------------------
  1584. 0000.000
  1585. 0000.000
  1586. -34338492.215397047
  1587. 0004.310
  1588. 7799461.4119
  1589. 16397.038491
  1590. 93901.57763026
  1591. -83028485.000
  1592. 74881.000
  1593. -24926804.04504742
  1594. (10 rows)
  1595. SELECT to_char(val, 'FM0999999999999999.999909999999999') FROM num_data;
  1596. to_char
  1597. -----------------------------
  1598. 0000000000000000.00000
  1599. 0000000000000000.00000
  1600. -0000000034338492.215397047
  1601. 0000000000000004.31000
  1602. 0000000007799461.41190
  1603. 0000000000016397.038491
  1604. 0000000000093901.57763026
  1605. -0000000083028485.00000
  1606. 0000000000074881.00000
  1607. -0000000024926804.04504742
  1608. (10 rows)
  1609. SELECT to_char(val, 'FM9999999990999999.099999999999999') FROM num_data;
  1610. to_char
  1611. ---------------------
  1612. 0000000.0
  1613. 0000000.0
  1614. -34338492.215397047
  1615. 0000004.31
  1616. 7799461.4119
  1617. 0016397.038491
  1618. 0093901.57763026
  1619. -83028485.0
  1620. 0074881.0
  1621. -24926804.04504742
  1622. (10 rows)
  1623. SELECT to_char(val, 'L9999999999999999.099999999999999') FROM num_data;
  1624. to_char
  1625. ------------------------------------
  1626. .000000000000000
  1627. .000000000000000
  1628. -34338492.215397047000000
  1629. 4.310000000000000
  1630. 7799461.411900000000000
  1631. 16397.038491000000000
  1632. 93901.577630260000000
  1633. -83028485.000000000000000
  1634. 74881.000000000000000
  1635. -24926804.045047420000000
  1636. (10 rows)
  1637. SELECT to_char(val, 'FM9999999999999999.99999999999999') FROM num_data;
  1638. to_char
  1639. ---------------------
  1640. 0.
  1641. 0.
  1642. -34338492.215397047
  1643. 4.31
  1644. 7799461.4119
  1645. 16397.038491
  1646. 93901.57763026
  1647. -83028485.
  1648. 74881.
  1649. -24926804.04504742
  1650. (10 rows)
  1651. SELECT to_char(val, 'S 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 . 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9') FROM num_data;
  1652. to_char
  1653. -----------------------------------------------------------------------
  1654. +. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  1655. +. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  1656. -3 4 3 3 8 4 9 2 . 2 1 5 3 9 7 0 4 7 0 0 0 0 0 0 0 0
  1657. +4 . 3 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  1658. +7 7 9 9 4 6 1 . 4 1 1 9 0 0 0 0 0 0 0 0 0 0 0 0 0
  1659. +1 6 3 9 7 . 0 3 8 4 9 1 0 0 0 0 0 0 0 0 0 0 0
  1660. +9 3 9 0 1 . 5 7 7 6 3 0 2 6 0 0 0 0 0 0 0 0 0
  1661. -8 3 0 2 8 4 8 5 . 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  1662. +7 4 8 8 1 . 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  1663. -2 4 9 2 6 8 0 4 . 0 4 5 0 4 7 4 2 0 0 0 0 0 0 0 0 0
  1664. (10 rows)
  1665. SELECT to_char(val, 'FMS 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 . 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9') FROM num_data;
  1666. to_char
  1667. -------------------------------------------------------
  1668. +0 .
  1669. +0 .
  1670. -3 4 3 3 8 4 9 2 . 2 1 5 3 9 7 0 4 7
  1671. +4 . 3 1
  1672. +7 7 9 9 4 6 1 . 4 1 1 9
  1673. +1 6 3 9 7 . 0 3 8 4 9 1
  1674. +9 3 9 0 1 . 5 7 7 6 3 0 2 6
  1675. -8 3 0 2 8 4 8 5 .
  1676. +7 4 8 8 1 .
  1677. -2 4 9 2 6 8 0 4 . 0 4 5 0 4 7 4 2
  1678. (10 rows)
  1679. SELECT to_char(val, E'99999 "text" 9999 "9999" 999 "\\"text between quote marks\\"" 9999') FROM num_data;
  1680. to_char
  1681. -----------------------------------------------------------
  1682. text 9999 "text between quote marks" 0
  1683. text 9999 "text between quote marks" 0
  1684. text -3 9999 433 "text between quote marks" 8492
  1685. text 9999 "text between quote marks" 4
  1686. text 9999 779 "text between quote marks" 9461
  1687. text 9999 1 "text between quote marks" 6397
  1688. text 9999 9 "text between quote marks" 3902
  1689. text -8 9999 302 "text between quote marks" 8485
  1690. text 9999 7 "text between quote marks" 4881
  1691. text -2 9999 492 "text between quote marks" 6804
  1692. (10 rows)
  1693. SELECT to_char(val, '999999SG9999999999') FROM num_data;
  1694. to_char
  1695. -------------------
  1696. + 0
  1697. + 0
  1698. - 34338492
  1699. + 4
  1700. + 7799461
  1701. + 16397
  1702. + 93902
  1703. - 83028485
  1704. + 74881
  1705. - 24926804
  1706. (10 rows)
  1707. SELECT to_char(val, 'FM9999999999999999.999999999999999') FROM num_data;
  1708. to_char
  1709. ---------------------
  1710. 0.
  1711. 0.
  1712. -34338492.215397047
  1713. 4.31
  1714. 7799461.4119
  1715. 16397.038491
  1716. 93901.57763026
  1717. -83028485.
  1718. 74881.
  1719. -24926804.04504742
  1720. (10 rows)
  1721. SELECT to_char(val, '9.999EEEE') FROM num_data;
  1722. to_char
  1723. ------------
  1724. 0.000e+00
  1725. 0.000e+00
  1726. -3.434e+07
  1727. 4.310e+00
  1728. 7.799e+06
  1729. 1.640e+04
  1730. 9.390e+04
  1731. -8.303e+07
  1732. 7.488e+04
  1733. -2.493e+07
  1734. (10 rows)
  1735. WITH v(val) AS
  1736. (VALUES('0'::numeric),('-4.2'),('4.2e9'),('1.2e-5'),('inf'),('-inf'),('nan'))
  1737. SELECT val,
  1738. to_char(val, '9.999EEEE') as numeric,
  1739. to_char(val::float8, '9.999EEEE') as float8,
  1740. to_char(val::float4, '9.999EEEE') as float4
  1741. FROM v;
  1742. val | numeric | float8 | float4
  1743. ------------+------------+------------+------------
  1744. 0 | 0.000e+00 | 0.000e+00 | 0.000e+00
  1745. -4.2 | -4.200e+00 | -4.200e+00 | -4.200e+00
  1746. 4200000000 | 4.200e+09 | 4.200e+09 | 4.200e+09
  1747. 0.000012 | 1.200e-05 | 1.200e-05 | 1.200e-05
  1748. Infinity | #.####### | #.####### | #.#######
  1749. -Infinity | #.####### | #.####### | #.#######
  1750. NaN | #.####### | #.####### | #.#######
  1751. (7 rows)
  1752. WITH v(exp) AS
  1753. (VALUES(-16379),(-16378),(-1234),(-789),(-45),(-5),(-4),(-3),(-2),(-1),(0),
  1754. (1),(2),(3),(4),(5),(38),(275),(2345),(45678),(131070),(131071))
  1755. SELECT exp,
  1756. to_char(('1.2345e'||exp)::numeric, '9.999EEEE') as numeric
  1757. FROM v;
  1758. exp | numeric
  1759. --------+----------------
  1760. -16379 | 1.235e-16379
  1761. -16378 | 1.235e-16378
  1762. -1234 | 1.235e-1234
  1763. -789 | 1.235e-789
  1764. -45 | 1.235e-45
  1765. -5 | 1.235e-05
  1766. -4 | 1.235e-04
  1767. -3 | 1.235e-03
  1768. -2 | 1.235e-02
  1769. -1 | 1.235e-01
  1770. 0 | 1.235e+00
  1771. 1 | 1.235e+01
  1772. 2 | 1.235e+02
  1773. 3 | 1.235e+03
  1774. 4 | 1.235e+04
  1775. 5 | 1.235e+05
  1776. 38 | 1.235e+38
  1777. 275 | 1.235e+275
  1778. 2345 | 1.235e+2345
  1779. 45678 | 1.235e+45678
  1780. 131070 | 1.235e+131070
  1781. 131071 | 1.235e+131071
  1782. (22 rows)
  1783. WITH v(val) AS
  1784. (VALUES('0'::numeric),('-4.2'),('4.2e9'),('1.2e-5'),('inf'),('-inf'),('nan'))
  1785. SELECT val,
  1786. to_char(val, 'MI9999999999.99') as numeric,
  1787. to_char(val::float8, 'MI9999999999.99') as float8,
  1788. to_char(val::float4, 'MI9999999999.99') as float4
  1789. FROM v;
  1790. val | numeric | float8 | float4
  1791. ------------+----------------+----------------+----------------
  1792. 0 | .00 | .00 | .00
  1793. -4.2 | - 4.20 | - 4.20 | - 4.20
  1794. 4200000000 | 4200000000.00 | 4200000000.00 | 4200000000
  1795. 0.000012 | .00 | .00 | .00
  1796. Infinity | Infinity | Infinity | Infinity
  1797. -Infinity | - Infinity | - Infinity | - Infinity
  1798. NaN | NaN | NaN | NaN
  1799. (7 rows)
  1800. WITH v(val) AS
  1801. (VALUES('0'::numeric),('-4.2'),('4.2e9'),('1.2e-5'),('inf'),('-inf'),('nan'))
  1802. SELECT val,
  1803. to_char(val, 'MI99.99') as numeric,
  1804. to_char(val::float8, 'MI99.99') as float8,
  1805. to_char(val::float4, 'MI99.99') as float4
  1806. FROM v;
  1807. val | numeric | float8 | float4
  1808. ------------+---------+--------+--------
  1809. 0 | .00 | .00 | .00
  1810. -4.2 | - 4.20 | - 4.20 | - 4.20
  1811. 4200000000 | ##.## | ##.## | ##.
  1812. 0.000012 | .00 | .00 | .00
  1813. Infinity | ##.## | ##.## | ##.
  1814. -Infinity | -##.## | -##.## | -##.
  1815. NaN | ##.## | ##.## | ##.##
  1816. (7 rows)
  1817. SELECT to_char('100'::numeric, 'FM999.9');
  1818. to_char
  1819. ---------
  1820. 100.
  1821. (1 row)
  1822. SELECT to_char('100'::numeric, 'FM999.');
  1823. to_char
  1824. ---------
  1825. 100
  1826. (1 row)
  1827. SELECT to_char('100'::numeric, 'FM999');
  1828. to_char
  1829. ---------
  1830. 100
  1831. (1 row)
  1832. -- Check parsing of literal text in a format string
  1833. SELECT to_char('100'::numeric, 'foo999');
  1834. to_char
  1835. ---------
  1836. foo 100
  1837. (1 row)
  1838. SELECT to_char('100'::numeric, 'f\oo999');
  1839. to_char
  1840. ----------
  1841. f\oo 100
  1842. (1 row)
  1843. SELECT to_char('100'::numeric, 'f\\oo999');
  1844. to_char
  1845. -----------
  1846. f\\oo 100
  1847. (1 row)
  1848. SELECT to_char('100'::numeric, 'f\"oo999');
  1849. to_char
  1850. ----------
  1851. f"oo 100
  1852. (1 row)
  1853. SELECT to_char('100'::numeric, 'f\\"oo999');
  1854. to_char
  1855. -----------
  1856. f\"oo 100
  1857. (1 row)
  1858. SELECT to_char('100'::numeric, 'f"ool"999');
  1859. to_char
  1860. ----------
  1861. fool 100
  1862. (1 row)
  1863. SELECT to_char('100'::numeric, 'f"\ool"999');
  1864. to_char
  1865. ----------
  1866. fool 100
  1867. (1 row)
  1868. SELECT to_char('100'::numeric, 'f"\\ool"999');
  1869. to_char
  1870. -----------
  1871. f\ool 100
  1872. (1 row)
  1873. SELECT to_char('100'::numeric, 'f"ool\"999');
  1874. to_char
  1875. ----------
  1876. fool"999
  1877. (1 row)
  1878. SELECT to_char('100'::numeric, 'f"ool\\"999');
  1879. to_char
  1880. -----------
  1881. fool\ 100
  1882. (1 row)
  1883. -- TO_NUMBER()
  1884. --
  1885. SET lc_numeric = 'C';
  1886. SELECT to_number('-34,338,492', '99G999G999');
  1887. to_number
  1888. -----------
  1889. -34338492
  1890. (1 row)
  1891. SELECT to_number('-34,338,492.654,878', '99G999G999D999G999');
  1892. to_number
  1893. ------------------
  1894. -34338492.654878
  1895. (1 row)
  1896. SELECT to_number('<564646.654564>', '999999.999999PR');
  1897. to_number
  1898. ----------------
  1899. -564646.654564
  1900. (1 row)
  1901. SELECT to_number('0.00001-', '9.999999S');
  1902. to_number
  1903. -----------
  1904. -0.00001
  1905. (1 row)
  1906. SELECT to_number('5.01-', 'FM9.999999S');
  1907. to_number
  1908. -----------
  1909. -5.01
  1910. (1 row)
  1911. SELECT to_number('5.01-', 'FM9.999999MI');
  1912. to_number
  1913. -----------
  1914. -5.01
  1915. (1 row)
  1916. SELECT to_number('5 4 4 4 4 8 . 7 8', '9 9 9 9 9 9 . 9 9');
  1917. to_number
  1918. -----------
  1919. 544448.78
  1920. (1 row)
  1921. SELECT to_number('.01', 'FM9.99');
  1922. to_number
  1923. -----------
  1924. 0.01
  1925. (1 row)
  1926. SELECT to_number('.0', '99999999.99999999');
  1927. to_number
  1928. -----------
  1929. 0.0
  1930. (1 row)
  1931. SELECT to_number('0', '99.99');
  1932. to_number
  1933. -----------
  1934. 0
  1935. (1 row)
  1936. SELECT to_number('.-01', 'S99.99');
  1937. to_number
  1938. -----------
  1939. -0.01
  1940. (1 row)
  1941. SELECT to_number('.01-', '99.99S');
  1942. to_number
  1943. -----------
  1944. -0.01
  1945. (1 row)
  1946. SELECT to_number(' . 0 1-', ' 9 9 . 9 9 S');
  1947. to_number
  1948. -----------
  1949. -0.01
  1950. (1 row)
  1951. SELECT to_number('34,50','999,99');
  1952. to_number
  1953. -----------
  1954. 3450
  1955. (1 row)
  1956. SELECT to_number('123,000','999G');
  1957. to_number
  1958. -----------
  1959. 123
  1960. (1 row)
  1961. SELECT to_number('123456','999G999');
  1962. to_number
  1963. -----------
  1964. 123456
  1965. (1 row)
  1966. SELECT to_number('$1234.56','L9,999.99');
  1967. to_number
  1968. -----------
  1969. 1234.56
  1970. (1 row)
  1971. SELECT to_number('$1234.56','L99,999.99');
  1972. to_number
  1973. -----------
  1974. 1234.56
  1975. (1 row)
  1976. SELECT to_number('$1,234.56','L99,999.99');
  1977. to_number
  1978. -----------
  1979. 1234.56
  1980. (1 row)
  1981. SELECT to_number('1234.56','L99,999.99');
  1982. to_number
  1983. -----------
  1984. 1234.56
  1985. (1 row)
  1986. SELECT to_number('1,234.56','L99,999.99');
  1987. to_number
  1988. -----------
  1989. 1234.56
  1990. (1 row)
  1991. SELECT to_number('42nd', '99th');
  1992. to_number
  1993. -----------
  1994. 42
  1995. (1 row)
  1996. RESET lc_numeric;
  1997. --
  1998. -- Input syntax
  1999. --
  2000. CREATE TABLE num_input_test (n1 numeric);
  2001. -- good inputs
  2002. INSERT INTO num_input_test(n1) VALUES (' 123');
  2003. INSERT INTO num_input_test(n1) VALUES (' 3245874 ');
  2004. INSERT INTO num_input_test(n1) VALUES (' -93853');
  2005. INSERT INTO num_input_test(n1) VALUES ('555.50');
  2006. INSERT INTO num_input_test(n1) VALUES ('-555.50');
  2007. INSERT INTO num_input_test(n1) VALUES ('NaN ');
  2008. INSERT INTO num_input_test(n1) VALUES (' nan');
  2009. INSERT INTO num_input_test(n1) VALUES (' inf ');
  2010. INSERT INTO num_input_test(n1) VALUES (' +inf ');
  2011. INSERT INTO num_input_test(n1) VALUES (' -inf ');
  2012. INSERT INTO num_input_test(n1) VALUES (' Infinity ');
  2013. INSERT INTO num_input_test(n1) VALUES (' +inFinity ');
  2014. INSERT INTO num_input_test(n1) VALUES (' -INFINITY ');
  2015. -- bad inputs
  2016. INSERT INTO num_input_test(n1) VALUES (' ');
  2017. ERROR: invalid input syntax for type numeric: " "
  2018. LINE 1: INSERT INTO num_input_test(n1) VALUES (' ');
  2019. ^
  2020. INSERT INTO num_input_test(n1) VALUES (' 1234 %');
  2021. ERROR: invalid input syntax for type numeric: " 1234 %"
  2022. LINE 1: INSERT INTO num_input_test(n1) VALUES (' 1234 %');
  2023. ^
  2024. INSERT INTO num_input_test(n1) VALUES ('xyz');
  2025. ERROR: invalid input syntax for type numeric: "xyz"
  2026. LINE 1: INSERT INTO num_input_test(n1) VALUES ('xyz');
  2027. ^
  2028. INSERT INTO num_input_test(n1) VALUES ('- 1234');
  2029. ERROR: invalid input syntax for type numeric: "- 1234"
  2030. LINE 1: INSERT INTO num_input_test(n1) VALUES ('- 1234');
  2031. ^
  2032. INSERT INTO num_input_test(n1) VALUES ('5 . 0');
  2033. ERROR: invalid input syntax for type numeric: "5 . 0"
  2034. LINE 1: INSERT INTO num_input_test(n1) VALUES ('5 . 0');
  2035. ^
  2036. INSERT INTO num_input_test(n1) VALUES ('5. 0 ');
  2037. ERROR: invalid input syntax for type numeric: "5. 0 "
  2038. LINE 1: INSERT INTO num_input_test(n1) VALUES ('5. 0 ');
  2039. ^
  2040. INSERT INTO num_input_test(n1) VALUES ('');
  2041. ERROR: invalid input syntax for type numeric: ""
  2042. LINE 1: INSERT INTO num_input_test(n1) VALUES ('');
  2043. ^
  2044. INSERT INTO num_input_test(n1) VALUES (' N aN ');
  2045. ERROR: invalid input syntax for type numeric: " N aN "
  2046. LINE 1: INSERT INTO num_input_test(n1) VALUES (' N aN ');
  2047. ^
  2048. INSERT INTO num_input_test(n1) VALUES ('+ infinity');
  2049. ERROR: invalid input syntax for type numeric: "+ infinity"
  2050. LINE 1: INSERT INTO num_input_test(n1) VALUES ('+ infinity');
  2051. ^
  2052. SELECT * FROM num_input_test;
  2053. n1
  2054. -----------
  2055. 123
  2056. 3245874
  2057. -93853
  2058. 555.50
  2059. -555.50
  2060. NaN
  2061. NaN
  2062. Infinity
  2063. Infinity
  2064. -Infinity
  2065. Infinity
  2066. Infinity
  2067. -Infinity
  2068. (13 rows)
  2069. --
  2070. -- Test some corner cases for multiplication
  2071. --
  2072. select 4790999999999999999999999999999999999999999999999999999999999999999999999999999999999999 * 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999;
  2073. ?column?
  2074. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2075. 47909999999999999999999999999999999999999999999999999999999999999999999999999999999999985209000000000000000000000000000000000000000000000000000000000000000000000000000000000001
  2076. (1 row)
  2077. select 4789999999999999999999999999999999999999999999999999999999999999999999999999999999999999 * 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999;
  2078. ?column?
  2079. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2080. 47899999999999999999999999999999999999999999999999999999999999999999999999999999999999985210000000000000000000000000000000000000000000000000000000000000000000000000000000000001
  2081. (1 row)
  2082. select 4770999999999999999999999999999999999999999999999999999999999999999999999999999999999999 * 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999;
  2083. ?column?
  2084. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2085. 47709999999999999999999999999999999999999999999999999999999999999999999999999999999999985229000000000000000000000000000000000000000000000000000000000000000000000000000000000001
  2086. (1 row)
  2087. select 4769999999999999999999999999999999999999999999999999999999999999999999999999999999999999 * 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999;
  2088. ?column?
  2089. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2090. 47699999999999999999999999999999999999999999999999999999999999999999999999999999999999985230000000000000000000000000000000000000000000000000000000000000000000000000000000000001
  2091. (1 row)
  2092. select trim_scale((0.1 - 2e-16383) * (0.1 - 3e-16383));
  2093. trim_scale
  2094. ------------
  2095. 0.01
  2096. (1 row)
  2097. --
  2098. -- Test some corner cases for division
  2099. --
  2100. select 999999999999999999999::numeric/1000000000000000000000;
  2101. ?column?
  2102. ------------------------
  2103. 1.00000000000000000000
  2104. (1 row)
  2105. select div(999999999999999999999::numeric,1000000000000000000000);
  2106. div
  2107. -----
  2108. 0
  2109. (1 row)
  2110. select mod(999999999999999999999::numeric,1000000000000000000000);
  2111. mod
  2112. -----------------------
  2113. 999999999999999999999
  2114. (1 row)
  2115. select div(-9999999999999999999999::numeric,1000000000000000000000);
  2116. div
  2117. -----
  2118. -9
  2119. (1 row)
  2120. select mod(-9999999999999999999999::numeric,1000000000000000000000);
  2121. mod
  2122. ------------------------
  2123. -999999999999999999999
  2124. (1 row)
  2125. select div(-9999999999999999999999::numeric,1000000000000000000000)*1000000000000000000000 + mod(-9999999999999999999999::numeric,1000000000000000000000);
  2126. ?column?
  2127. -------------------------
  2128. -9999999999999999999999
  2129. (1 row)
  2130. select mod (70.0,70) ;
  2131. mod
  2132. -----
  2133. 0.0
  2134. (1 row)
  2135. select div (70.0,70) ;
  2136. div
  2137. -----
  2138. 1
  2139. (1 row)
  2140. select 70.0 / 70 ;
  2141. ?column?
  2142. ------------------------
  2143. 1.00000000000000000000
  2144. (1 row)
  2145. select 12345678901234567890 % 123;
  2146. ?column?
  2147. ----------
  2148. 78
  2149. (1 row)
  2150. select 12345678901234567890 / 123;
  2151. ?column?
  2152. --------------------
  2153. 100371373180768845
  2154. (1 row)
  2155. select div(12345678901234567890, 123);
  2156. div
  2157. --------------------
  2158. 100371373180768844
  2159. (1 row)
  2160. select div(12345678901234567890, 123) * 123 + 12345678901234567890 % 123;
  2161. ?column?
  2162. ----------------------
  2163. 12345678901234567890
  2164. (1 row)
  2165. --
  2166. -- Test some corner cases for square root
  2167. --
  2168. select sqrt(1.000000000000003::numeric);
  2169. sqrt
  2170. -------------------
  2171. 1.000000000000001
  2172. (1 row)
  2173. select sqrt(1.000000000000004::numeric);
  2174. sqrt
  2175. -------------------
  2176. 1.000000000000002
  2177. (1 row)
  2178. select sqrt(96627521408608.56340355805::numeric);
  2179. sqrt
  2180. ---------------------
  2181. 9829929.87811248648
  2182. (1 row)
  2183. select sqrt(96627521408608.56340355806::numeric);
  2184. sqrt
  2185. ---------------------
  2186. 9829929.87811248649
  2187. (1 row)
  2188. select sqrt(515549506212297735.073688290367::numeric);
  2189. sqrt
  2190. ------------------------
  2191. 718017761.766585921184
  2192. (1 row)
  2193. select sqrt(515549506212297735.073688290368::numeric);
  2194. sqrt
  2195. ------------------------
  2196. 718017761.766585921185
  2197. (1 row)
  2198. select sqrt(8015491789940783531003294973900306::numeric);
  2199. sqrt
  2200. -------------------
  2201. 89529278953540017
  2202. (1 row)
  2203. select sqrt(8015491789940783531003294973900307::numeric);
  2204. sqrt
  2205. -------------------
  2206. 89529278953540018
  2207. (1 row)
  2208. --
  2209. -- Test code path for raising to integer powers
  2210. --
  2211. select 10.0 ^ -2147483648 as rounds_to_zero;
  2212. rounds_to_zero
  2213. --------------------
  2214. 0.0000000000000000
  2215. (1 row)
  2216. select 10.0 ^ -2147483647 as rounds_to_zero;
  2217. rounds_to_zero
  2218. --------------------
  2219. 0.0000000000000000
  2220. (1 row)
  2221. select 10.0 ^ 2147483647 as overflows;
  2222. ERROR: value overflows numeric format
  2223. select 117743296169.0 ^ 1000000000 as overflows;
  2224. ERROR: value overflows numeric format
  2225. -- cases that used to return inaccurate results
  2226. select 3.789 ^ 21;
  2227. ?column?
  2228. --------------------------------
  2229. 1409343026052.8716016316022141
  2230. (1 row)
  2231. select 3.789 ^ 35;
  2232. ?column?
  2233. ----------------------------------------
  2234. 177158169650516670809.3820586142670135
  2235. (1 row)
  2236. select 1.2 ^ 345;
  2237. ?column?
  2238. -----------------------------------------------
  2239. 2077446682327378559843444695.5827049735727869
  2240. (1 row)
  2241. select 0.12 ^ (-20);
  2242. ?column?
  2243. --------------------------------------
  2244. 2608405330458882702.5529619561355838
  2245. (1 row)
  2246. select 1.000000000123 ^ (-2147483648);
  2247. ?column?
  2248. --------------------
  2249. 0.7678656556403084
  2250. (1 row)
  2251. select coalesce(nullif(0.9999999999 ^ 23300000000000, 0), 0) as rounds_to_zero;
  2252. rounds_to_zero
  2253. ----------------
  2254. 0
  2255. (1 row)
  2256. select round(((1 - 1.500012345678e-1000) ^ 1.45e1003) * 1e1000);
  2257. round
  2258. ----------------------------------------------------------
  2259. 25218976308958387188077465658068501556514992509509282366
  2260. (1 row)
  2261. -- cases that used to error out
  2262. select 0.12 ^ (-25);
  2263. ?column?
  2264. -------------------------------------------
  2265. 104825960103961013959336.4983657883169110
  2266. (1 row)
  2267. select 0.5678 ^ (-85);
  2268. ?column?
  2269. ----------------------------------------
  2270. 782333637740774446257.7719390061997396
  2271. (1 row)
  2272. select coalesce(nullif(0.9999999999 ^ 70000000000000, 0), 0) as underflows;
  2273. underflows
  2274. ------------
  2275. 0
  2276. (1 row)
  2277. -- negative base to integer powers
  2278. select (-1.0) ^ 2147483646;
  2279. ?column?
  2280. --------------------
  2281. 1.0000000000000000
  2282. (1 row)
  2283. select (-1.0) ^ 2147483647;
  2284. ?column?
  2285. ---------------------
  2286. -1.0000000000000000
  2287. (1 row)
  2288. select (-1.0) ^ 2147483648;
  2289. ?column?
  2290. --------------------
  2291. 1.0000000000000000
  2292. (1 row)
  2293. select (-1.0) ^ 1000000000000000;
  2294. ?column?
  2295. --------------------
  2296. 1.0000000000000000
  2297. (1 row)
  2298. select (-1.0) ^ 1000000000000001;
  2299. ?column?
  2300. ---------------------
  2301. -1.0000000000000000
  2302. (1 row)
  2303. --
  2304. -- Tests for raising to non-integer powers
  2305. --
  2306. -- special cases
  2307. select 0.0 ^ 0.0;
  2308. ?column?
  2309. --------------------
  2310. 1.0000000000000000
  2311. (1 row)
  2312. select (-12.34) ^ 0.0;
  2313. ?column?
  2314. --------------------
  2315. 1.0000000000000000
  2316. (1 row)
  2317. select 12.34 ^ 0.0;
  2318. ?column?
  2319. --------------------
  2320. 1.0000000000000000
  2321. (1 row)
  2322. select 0.0 ^ 12.34;
  2323. ?column?
  2324. --------------------
  2325. 0.0000000000000000
  2326. (1 row)
  2327. -- NaNs
  2328. select 'NaN'::numeric ^ 'NaN'::numeric;
  2329. ?column?
  2330. ----------
  2331. NaN
  2332. (1 row)
  2333. select 'NaN'::numeric ^ 0;
  2334. ?column?
  2335. ----------
  2336. 1
  2337. (1 row)
  2338. select 'NaN'::numeric ^ 1;
  2339. ?column?
  2340. ----------
  2341. NaN
  2342. (1 row)
  2343. select 0 ^ 'NaN'::numeric;
  2344. ?column?
  2345. ----------
  2346. NaN
  2347. (1 row)
  2348. select 1 ^ 'NaN'::numeric;
  2349. ?column?
  2350. ----------
  2351. 1
  2352. (1 row)
  2353. -- invalid inputs
  2354. select 0.0 ^ (-12.34);
  2355. ERROR: zero raised to a negative power is undefined
  2356. select (-12.34) ^ 1.2;
  2357. ERROR: a negative number raised to a non-integer power yields a complex result
  2358. -- cases that used to generate inaccurate results
  2359. select 32.1 ^ 9.8;
  2360. ?column?
  2361. --------------------
  2362. 580429286790711.10
  2363. (1 row)
  2364. select 32.1 ^ (-9.8);
  2365. ?column?
  2366. ----------------------------------
  2367. 0.000000000000001722862754788209
  2368. (1 row)
  2369. select 12.3 ^ 45.6;
  2370. ?column?
  2371. ------------------------------------------------------
  2372. 50081010321492803393171165777624533697036806969694.9
  2373. (1 row)
  2374. select 12.3 ^ (-45.6);
  2375. ?column?
  2376. ---------------------------------------------------------------------
  2377. 0.00000000000000000000000000000000000000000000000001996764828785491
  2378. (1 row)
  2379. -- big test
  2380. select 1.234 ^ 5678;
  2381. ?column?
  2382. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2383. 307239295662090741644584872593956173493568238595074141254349565406661439636598896798876823220904084953233015553994854875890890858118656468658643918169805277399402542281777901029346337707622181574346585989613344285010764501017625366742865066948856161360224801370482171458030533346309750557140549621313515752078638620714732831815297168231790779296290266207315344008883935010274044001522606235576584215999260117523114297033944018699691024106823438431754073086813382242140602291215149759520833200152654884259619588924545324.5973362312547382
  2384. (1 row)
  2385. --
  2386. -- Tests for EXP()
  2387. --
  2388. -- special cases
  2389. select exp(0.0);
  2390. exp
  2391. --------------------
  2392. 1.0000000000000000
  2393. (1 row)
  2394. select exp(1.0);
  2395. exp
  2396. --------------------
  2397. 2.7182818284590452
  2398. (1 row)
  2399. select exp(1.0::numeric(71,70));
  2400. exp
  2401. --------------------------------------------------------------------------
  2402. 2.7182818284590452353602874713526624977572470936999595749669676277240766
  2403. (1 row)
  2404. select exp('nan'::numeric);
  2405. exp
  2406. -----
  2407. NaN
  2408. (1 row)
  2409. select exp('inf'::numeric);
  2410. exp
  2411. ----------
  2412. Infinity
  2413. (1 row)
  2414. select exp('-inf'::numeric);
  2415. exp
  2416. -----
  2417. 0
  2418. (1 row)
  2419. select coalesce(nullif(exp(-5000::numeric), 0), 0) as rounds_to_zero;
  2420. rounds_to_zero
  2421. ----------------
  2422. 0
  2423. (1 row)
  2424. select coalesce(nullif(exp(-10000::numeric), 0), 0) as underflows;
  2425. underflows
  2426. ------------
  2427. 0
  2428. (1 row)
  2429. -- cases that used to generate inaccurate results
  2430. select exp(32.999);
  2431. exp
  2432. ---------------------
  2433. 214429043492155.053
  2434. (1 row)
  2435. select exp(-32.999);
  2436. exp
  2437. ----------------------------------
  2438. 0.000000000000004663547361468248
  2439. (1 row)
  2440. select exp(123.456);
  2441. exp
  2442. ------------------------------------------------------------
  2443. 413294435277809344957685441227343146614594393746575438.725
  2444. (1 row)
  2445. select exp(-123.456);
  2446. exp
  2447. -------------------------------------------------------------------------
  2448. 0.000000000000000000000000000000000000000000000000000002419582541264601
  2449. (1 row)
  2450. -- big test
  2451. select exp(1234.5678);
  2452. exp
  2453. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2454. 146549072930959479983482138503979804217622199675223653966270157446954995433819741094410764947112047906012815540251009949604426069672532417736057033099274204598385314594846509975629046864798765888104789074984927709616261452461385220475510438783429612447831614003668421849727379202555580791042606170523016207262965336641214601082882495255771621327088265411334088968112458492660609809762865582162764292604697957813514621259353683899630997077707406305730694385703091201347848855199354307506425820147289848677003277208302716466011827836279231.9667
  2455. (1 row)
  2456. --
  2457. -- Tests for generate_series
  2458. --
  2459. select * from generate_series(0.0::numeric, 4.0::numeric);
  2460. generate_series
  2461. -----------------
  2462. 0.0
  2463. 1.0
  2464. 2.0
  2465. 3.0
  2466. 4.0
  2467. (5 rows)
  2468. select * from generate_series(0.1::numeric, 4.0::numeric, 1.3::numeric);
  2469. generate_series
  2470. -----------------
  2471. 0.1
  2472. 1.4
  2473. 2.7
  2474. 4.0
  2475. (4 rows)
  2476. select * from generate_series(4.0::numeric, -1.5::numeric, -2.2::numeric);
  2477. generate_series
  2478. -----------------
  2479. 4.0
  2480. 1.8
  2481. -0.4
  2482. (3 rows)
  2483. -- Trigger errors
  2484. select * from generate_series(-100::numeric, 100::numeric, 0::numeric);
  2485. ERROR: step size cannot equal zero
  2486. select * from generate_series(-100::numeric, 100::numeric, 'nan'::numeric);
  2487. ERROR: step size cannot be NaN
  2488. select * from generate_series('nan'::numeric, 100::numeric, 10::numeric);
  2489. ERROR: start value cannot be NaN
  2490. select * from generate_series(0::numeric, 'nan'::numeric, 10::numeric);
  2491. ERROR: stop value cannot be NaN
  2492. select * from generate_series('inf'::numeric, 'inf'::numeric, 10::numeric);
  2493. ERROR: start value cannot be infinity
  2494. select * from generate_series(0::numeric, 'inf'::numeric, 10::numeric);
  2495. ERROR: stop value cannot be infinity
  2496. select * from generate_series(0::numeric, '42'::numeric, '-inf'::numeric);
  2497. ERROR: step size cannot be infinity
  2498. -- Checks maximum, output is truncated
  2499. select (i / (10::numeric ^ 131071))::numeric(1,0)
  2500. from generate_series(6 * (10::numeric ^ 131071),
  2501. 9 * (10::numeric ^ 131071),
  2502. 10::numeric ^ 131071) as a(i);
  2503. numeric
  2504. ---------
  2505. 6
  2506. 7
  2507. 8
  2508. 9
  2509. (4 rows)
  2510. -- Check usage with variables
  2511. select * from generate_series(1::numeric, 3::numeric) i, generate_series(i,3) j;
  2512. i | j
  2513. ---+---
  2514. 1 | 1
  2515. 1 | 2
  2516. 1 | 3
  2517. 2 | 2
  2518. 2 | 3
  2519. 3 | 3
  2520. (6 rows)
  2521. select * from generate_series(1::numeric, 3::numeric) i, generate_series(1,i) j;
  2522. i | j
  2523. ---+---
  2524. 1 | 1
  2525. 2 | 1
  2526. 2 | 2
  2527. 3 | 1
  2528. 3 | 2
  2529. 3 | 3
  2530. (6 rows)
  2531. select * from generate_series(1::numeric, 3::numeric) i, generate_series(1,5,i) j;
  2532. i | j
  2533. ---+---
  2534. 1 | 1
  2535. 1 | 2
  2536. 1 | 3
  2537. 1 | 4
  2538. 1 | 5
  2539. 2 | 1
  2540. 2 | 3
  2541. 2 | 5
  2542. 3 | 1
  2543. 3 | 4
  2544. (10 rows)
  2545. --
  2546. -- Tests for LN()
  2547. --
  2548. -- Invalid inputs
  2549. select ln(-12.34);
  2550. ERROR: cannot take logarithm of a negative number
  2551. select ln(0.0);
  2552. ERROR: cannot take logarithm of zero
  2553. -- Some random tests
  2554. select ln(1.2345678e-28);
  2555. ln
  2556. -----------------------------------------
  2557. -64.26166165451762991204894255882820859
  2558. (1 row)
  2559. select ln(0.0456789);
  2560. ln
  2561. ---------------------
  2562. -3.0861187944847439
  2563. (1 row)
  2564. select ln(0.349873948359354029493948309745709580730482050975);
  2565. ln
  2566. -----------------------------------------------------
  2567. -1.050182336912082775693991697979750253056317885460
  2568. (1 row)
  2569. select ln(0.99949452);
  2570. ln
  2571. -------------------------
  2572. -0.00050560779808326467
  2573. (1 row)
  2574. select ln(1.00049687395);
  2575. ln
  2576. ------------------------
  2577. 0.00049675054901370394
  2578. (1 row)
  2579. select ln(1234.567890123456789);
  2580. ln
  2581. --------------------
  2582. 7.1184763012977896
  2583. (1 row)
  2584. select ln(5.80397490724e5);
  2585. ln
  2586. --------------------
  2587. 13.271468476626518
  2588. (1 row)
  2589. select ln(9.342536355e34);
  2590. ln
  2591. --------------------
  2592. 80.522470935524187
  2593. (1 row)
  2594. --
  2595. -- Tests for LOG() (base 10)
  2596. --
  2597. -- invalid inputs
  2598. select log(-12.34);
  2599. ERROR: cannot take logarithm of a negative number
  2600. CONTEXT: SQL function "log" statement 1
  2601. select log(0.0);
  2602. ERROR: cannot take logarithm of zero
  2603. CONTEXT: SQL function "log" statement 1
  2604. -- some random tests
  2605. select log(1.234567e-89);
  2606. log
  2607. -----------------------------------------------------------------------------------------------------
  2608. -88.90848533591373725637496492944925187293052336306443143312825869985819779294142441287021741054275
  2609. (1 row)
  2610. select log(3.4634998359873254962349856073435545);
  2611. log
  2612. --------------------------------------
  2613. 0.5395151714070134409152404011959981
  2614. (1 row)
  2615. select log(9.999999999999999999);
  2616. log
  2617. ----------------------
  2618. 1.000000000000000000
  2619. (1 row)
  2620. select log(10.00000000000000000);
  2621. log
  2622. ---------------------
  2623. 1.00000000000000000
  2624. (1 row)
  2625. select log(10.00000000000000001);
  2626. log
  2627. ---------------------
  2628. 1.00000000000000000
  2629. (1 row)
  2630. select log(590489.45235237);
  2631. log
  2632. -------------------
  2633. 5.771212144411727
  2634. (1 row)
  2635. --
  2636. -- Tests for LOG() (arbitrary base)
  2637. --
  2638. -- invalid inputs
  2639. select log(-12.34, 56.78);
  2640. ERROR: cannot take logarithm of a negative number
  2641. select log(-12.34, -56.78);
  2642. ERROR: cannot take logarithm of a negative number
  2643. select log(12.34, -56.78);
  2644. ERROR: cannot take logarithm of a negative number
  2645. select log(0.0, 12.34);
  2646. ERROR: cannot take logarithm of zero
  2647. select log(12.34, 0.0);
  2648. ERROR: cannot take logarithm of zero
  2649. select log(1.0, 12.34);
  2650. ERROR: division by zero
  2651. -- some random tests
  2652. select log(1.23e-89, 6.4689e45);
  2653. log
  2654. ------------------------------------------------------------------------------------------------
  2655. -0.5152489207781856983977054971756484879653568168479201885425588841094788842469115325262329756
  2656. (1 row)
  2657. select log(0.99923, 4.58934e34);
  2658. log
  2659. ---------------------
  2660. -103611.55579544132
  2661. (1 row)
  2662. select log(1.000016, 8.452010e18);
  2663. log
  2664. --------------------
  2665. 2723830.2877097365
  2666. (1 row)
  2667. select log(3.1954752e47, 9.4792021e-73);
  2668. log
  2669. -------------------------------------------------------------------------------------
  2670. -1.51613372350688302142917386143459361608600157692779164475351842333265418126982165
  2671. (1 row)
  2672. --
  2673. -- Tests for scale()
  2674. --
  2675. select scale(numeric 'NaN');
  2676. scale
  2677. -------
  2678. (1 row)
  2679. select scale(numeric 'inf');
  2680. scale
  2681. -------
  2682. (1 row)
  2683. select scale(NULL::numeric);
  2684. scale
  2685. -------
  2686. (1 row)
  2687. select scale(1.12);
  2688. scale
  2689. -------
  2690. 2
  2691. (1 row)
  2692. select scale(0);
  2693. scale
  2694. -------
  2695. 0
  2696. (1 row)
  2697. select scale(0.00);
  2698. scale
  2699. -------
  2700. 2
  2701. (1 row)
  2702. select scale(1.12345);
  2703. scale
  2704. -------
  2705. 5
  2706. (1 row)
  2707. select scale(110123.12475871856128);
  2708. scale
  2709. -------
  2710. 14
  2711. (1 row)
  2712. select scale(-1123.12471856128);
  2713. scale
  2714. -------
  2715. 11
  2716. (1 row)
  2717. select scale(-13.000000000000000);
  2718. scale
  2719. -------
  2720. 15
  2721. (1 row)
  2722. --
  2723. -- Tests for min_scale()
  2724. --
  2725. select min_scale(numeric 'NaN') is NULL; -- should be true
  2726. ?column?
  2727. ----------
  2728. t
  2729. (1 row)
  2730. select min_scale(numeric 'inf') is NULL; -- should be true
  2731. ?column?
  2732. ----------
  2733. t
  2734. (1 row)
  2735. select min_scale(0); -- no digits
  2736. min_scale
  2737. -----------
  2738. 0
  2739. (1 row)
  2740. select min_scale(0.00); -- no digits again
  2741. min_scale
  2742. -----------
  2743. 0
  2744. (1 row)
  2745. select min_scale(1.0); -- no scale
  2746. min_scale
  2747. -----------
  2748. 0
  2749. (1 row)
  2750. select min_scale(1.1); -- scale 1
  2751. min_scale
  2752. -----------
  2753. 1
  2754. (1 row)
  2755. select min_scale(1.12); -- scale 2
  2756. min_scale
  2757. -----------
  2758. 2
  2759. (1 row)
  2760. select min_scale(1.123); -- scale 3
  2761. min_scale
  2762. -----------
  2763. 3
  2764. (1 row)
  2765. select min_scale(1.1234); -- scale 4, filled digit
  2766. min_scale
  2767. -----------
  2768. 4
  2769. (1 row)
  2770. select min_scale(1.12345); -- scale 5, 2 NDIGITS
  2771. min_scale
  2772. -----------
  2773. 5
  2774. (1 row)
  2775. select min_scale(1.1000); -- 1 pos in NDIGITS
  2776. min_scale
  2777. -----------
  2778. 1
  2779. (1 row)
  2780. select min_scale(1e100); -- very big number
  2781. min_scale
  2782. -----------
  2783. 0
  2784. (1 row)
  2785. --
  2786. -- Tests for trim_scale()
  2787. --
  2788. select trim_scale(numeric 'NaN');
  2789. trim_scale
  2790. ------------
  2791. NaN
  2792. (1 row)
  2793. select trim_scale(numeric 'inf');
  2794. trim_scale
  2795. ------------
  2796. Infinity
  2797. (1 row)
  2798. select trim_scale(1.120);
  2799. trim_scale
  2800. ------------
  2801. 1.12
  2802. (1 row)
  2803. select trim_scale(0);
  2804. trim_scale
  2805. ------------
  2806. 0
  2807. (1 row)
  2808. select trim_scale(0.00);
  2809. trim_scale
  2810. ------------
  2811. 0
  2812. (1 row)
  2813. select trim_scale(1.1234500);
  2814. trim_scale
  2815. ------------
  2816. 1.12345
  2817. (1 row)
  2818. select trim_scale(110123.12475871856128000);
  2819. trim_scale
  2820. -----------------------
  2821. 110123.12475871856128
  2822. (1 row)
  2823. select trim_scale(-1123.124718561280000000);
  2824. trim_scale
  2825. -------------------
  2826. -1123.12471856128
  2827. (1 row)
  2828. select trim_scale(-13.00000000000000000000);
  2829. trim_scale
  2830. ------------
  2831. -13
  2832. (1 row)
  2833. select trim_scale(1e100);
  2834. trim_scale
  2835. -------------------------------------------------------------------------------------------------------
  2836. 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  2837. (1 row)
  2838. --
  2839. -- Tests for SUM()
  2840. --
  2841. -- cases that need carry propagation
  2842. SELECT SUM(9999::numeric) FROM generate_series(1, 100000);
  2843. sum
  2844. -----------
  2845. 999900000
  2846. (1 row)
  2847. SELECT SUM((-9999)::numeric) FROM generate_series(1, 100000);
  2848. sum
  2849. ------------
  2850. -999900000
  2851. (1 row)
  2852. --
  2853. -- Tests for GCD()
  2854. --
  2855. SELECT a, b, gcd(a, b), gcd(a, -b), gcd(-b, a), gcd(-b, -a)
  2856. FROM (VALUES (0::numeric, 0::numeric),
  2857. (0::numeric, numeric 'NaN'),
  2858. (0::numeric, 46375::numeric),
  2859. (433125::numeric, 46375::numeric),
  2860. (43312.5::numeric, 4637.5::numeric),
  2861. (4331.250::numeric, 463.75000::numeric),
  2862. ('inf', '0'),
  2863. ('inf', '42'),
  2864. ('inf', 'inf')
  2865. ) AS v(a, b);
  2866. a | b | gcd | gcd | gcd | gcd
  2867. ----------+-----------+---------+---------+---------+---------
  2868. 0 | 0 | 0 | 0 | 0 | 0
  2869. 0 | NaN | NaN | NaN | NaN | NaN
  2870. 0 | 46375 | 46375 | 46375 | 46375 | 46375
  2871. 433125 | 46375 | 875 | 875 | 875 | 875
  2872. 43312.5 | 4637.5 | 87.5 | 87.5 | 87.5 | 87.5
  2873. 4331.250 | 463.75000 | 8.75000 | 8.75000 | 8.75000 | 8.75000
  2874. Infinity | 0 | NaN | NaN | NaN | NaN
  2875. Infinity | 42 | NaN | NaN | NaN | NaN
  2876. Infinity | Infinity | NaN | NaN | NaN | NaN
  2877. (9 rows)
  2878. --
  2879. -- Tests for LCM()
  2880. --
  2881. SELECT a,b, lcm(a, b), lcm(a, -b), lcm(-b, a), lcm(-b, -a)
  2882. FROM (VALUES (0::numeric, 0::numeric),
  2883. (0::numeric, numeric 'NaN'),
  2884. (0::numeric, 13272::numeric),
  2885. (13272::numeric, 13272::numeric),
  2886. (423282::numeric, 13272::numeric),
  2887. (42328.2::numeric, 1327.2::numeric),
  2888. (4232.820::numeric, 132.72000::numeric),
  2889. ('inf', '0'),
  2890. ('inf', '42'),
  2891. ('inf', 'inf')
  2892. ) AS v(a, b);
  2893. a | b | lcm | lcm | lcm | lcm
  2894. ----------+-----------+--------------+--------------+--------------+--------------
  2895. 0 | 0 | 0 | 0 | 0 | 0
  2896. 0 | NaN | NaN | NaN | NaN | NaN
  2897. 0 | 13272 | 0 | 0 | 0 | 0
  2898. 13272 | 13272 | 13272 | 13272 | 13272 | 13272
  2899. 423282 | 13272 | 11851896 | 11851896 | 11851896 | 11851896
  2900. 42328.2 | 1327.2 | 1185189.6 | 1185189.6 | 1185189.6 | 1185189.6
  2901. 4232.820 | 132.72000 | 118518.96000 | 118518.96000 | 118518.96000 | 118518.96000
  2902. Infinity | 0 | NaN | NaN | NaN | NaN
  2903. Infinity | 42 | NaN | NaN | NaN | NaN
  2904. Infinity | Infinity | NaN | NaN | NaN | NaN
  2905. (10 rows)
  2906. SELECT lcm(9999 * (10::numeric)^131068 + (10::numeric^131068 - 1), 2); -- overflow
  2907. ERROR: value overflows numeric format
  2908. --
  2909. -- Tests for factorial
  2910. --
  2911. SELECT factorial(4);
  2912. factorial
  2913. -----------
  2914. 24
  2915. (1 row)
  2916. SELECT factorial(15);
  2917. factorial
  2918. ---------------
  2919. 1307674368000
  2920. (1 row)
  2921. SELECT factorial(100000);
  2922. ERROR: value overflows numeric format
  2923. SELECT factorial(0);
  2924. factorial
  2925. -----------
  2926. 1
  2927. (1 row)
  2928. SELECT factorial(-4);
  2929. ERROR: factorial of a negative number is undefined
  2930. --
  2931. -- Tests for pg_lsn()
  2932. --
  2933. SELECT pg_lsn(23783416::numeric);
  2934. pg_lsn
  2935. -----------
  2936. 0/16AE7F8
  2937. (1 row)
  2938. SELECT pg_lsn(0::numeric);
  2939. pg_lsn
  2940. --------
  2941. 0/0
  2942. (1 row)
  2943. SELECT pg_lsn(18446744073709551615::numeric);
  2944. pg_lsn
  2945. -------------------
  2946. FFFFFFFF/FFFFFFFF
  2947. (1 row)
  2948. SELECT pg_lsn(-1::numeric);
  2949. ERROR: pg_lsn out of range
  2950. SELECT pg_lsn(18446744073709551616::numeric);
  2951. ERROR: pg_lsn out of range
  2952. SELECT pg_lsn('NaN'::numeric);
  2953. ERROR: cannot convert NaN to pg_lsn