Hi,
I'm having strange differences between the R function prod ad the F90
function product.
Processing the same vector C (see attachment). I get 2 different results:
prod(C) = 1.069678e-307
testProduct(C) = 0
where testProd is the following wrapping function:
testProd <- function(x) {
return(.Fortran('testProd', as.double(x), as.double(0),
as.double(0), as.integer(length(x))))
}
subroutine testProd(x, p, q, n)
implicit none
integer, intent (in) :: n
double precision, intent (in) :: x(n)
double precision, intent (out) :: p
double precision, intent (out) :: q
integer :: i
p = product(x)
q=1
do i = 1, n
q = q*x(i)
end do
end subroutine testProd
I check the lowest possible number and seems to be the same for both R
and F90.
Can anyone help me understanding this behaviour?
Thank you in advance
Regards,
Filippo
-------------- next part --------------
c(0.126667774727727, 0.126778508335206, 0.126889731437094, 0.127001445486345,
0.127113651944097, 0.127226352279715, 0.127339547970833, 0.127453240503398,
0.127567431371714, 0.127682122078482, 0.127797314134848, 0.127913009060448,
0.128029208383447, 0.128145913640589, 0.128263126377241, 0.128380848147438,
0.128499080513928, 0.128617825048222, 0.128737083330636, 0.128856856950339,
0.128977147505404, 0.129097956602849, 0.129219285858691, 0.129341136897992,
0.129463511354905, 0.129586410872726, 0.129709837103945, 0.12983379171029,
0.129958276362782, 0.130083292741782, 0.130208842537045, 0.130334927447768,
0.130461549182643, 0.130588709459909, 0.130716410007402, 0.130844652562612,
0.130973438872731, 0.13110277069471, 0.131232649795309, 0.131363077951156,
0.131494056948797, 0.131625588584752, 0.131757674665574, 0.131890317007896,
0.132023517438499, 0.132157277794358, 0.132291599922703, 0.132426485681077,
0.132561936937394, 0.132697955569994, 0.132834543467704, 0.132971702529897,
0.133109434666551, 0.133247741798307, 0.133386625856532, 0.13352608878338,
0.133666132531848, 0.133806759065846, 0.133947970360249, 0.134089768400969,
0.134232155185011, 0.134375132720541, 0.134518703026945, 0.1346628681349,
0.13480763008643, 0.134952990934981, 0.135098952745478, 0.135245517594397,
0.13539268756983, 0.13554046477155, 0.135688851311081, 0.135837849311768,
0.13598746090884, 0.136137688249485, 0.136288533492915, 0.13643999881044,
0.136592086385536, 0.136744798413917, 0.136898137103608, 0.137052104675016,
0.137206703361001, 0.137361935406953, 0.137517803070863, 0.137674308623401,
0.137831454347986, 0.137989242540865, 0.138147675511187, 0.138306755581082,
0.138466485085736, 0.13862686637347, 0.13878790180582, 0.138949593757609,
0.139111944617036, 0.13927495678575, 0.139438632678933, 0.139602974725378,
0.139767985367577, 0.139933667061797, 0.140100022278169, 0.140267053500766,
0.140434763227692, 0.140603153971164, 0.140772228257601, 0.140941988627706,
0.141112437636557, 0.14128357785369, 0.141455411863193, 0.141627942263791,
0.141801171668934, 0.141975102706893, 0.142149738020846, 0.142325080268972,
0.14250113212454, 0.142677896276008, 0.14285537542711, 0.143033572296957,
0.143212489620126, 0.143392130146759, 0.14357249664266, 0.143753591889391,
0.14393541868437, 0.144117979840971, 0.144301278188622, 0.144485316572906,
0.144670097855664, 0.144855624915093, 0.14504190064585, 0.145228927959158,
0.145416709782907, 0.145605249061759, 0.145794548757257, 0.145984611847927,
0.146175441329391, 0.146367040214468, 0.14655941153329, 0.146752558333409,
0.146946483679905, 0.147141190655504, 0.147336682360684, 0.147532961913792,
0.147730032451156, 0.147927897127204, 0.148126559114576, 0.148326021604241,
0.148526287805616, 0.148727360946687, 0.148929244274124, 0.149131941053405,
0.149335454568934, 0.149539788124169, 0.149744945041738, 0.149950928663571,
0.150157742351019, 0.150365389484985, 0.150573873466047, 0.150783197714589,
0.150993365670932, 0.151204380795458, 0.151416246568747, 0.15162896649171,
0.151842544085717, 0.152056982892734, 0.15227228647546, 0.152488458417464,
0.152705502323319, 0.152923421818742, 0.153142220550736, 0.153361902187731,
0.15358247041972, 0.153803928958412, 0.154026281537366, 0.154249531912146,
0.15447368386046, 0.154698741182311, 0.154924707700148, 0.15515158725901,
0.155379383726686, 0.155608100993858, 0.155837742974264, 0.156068313604844,
0.156299816845904, 0.15653225668127, 0.156765637118446, 0.156999962188775,
0.157235235947601, 0.15747146247443, 0.157708645873097, 0.157946790271927,
0.158185899823904, 0.158425978706841, 0.158667031123545, 0.158909061301989,
0.159152073495486, 0.159396071982862, 0.159641061068628, 0.15988704508316,
0.160134028382875, 0.160382015350409, 0.160631010394801, 0.16088101795167,
0.161132042483405, 0.161384088479345, 0.161637160455966, 0.161891262957074,
0.162146400553988, 0.162402577845737, 0.162659799459248, 0.162918070049544,
0.163177394299939, 0.163437776922235, 0.163699222656923, 0.16396173627338,
0.164225322570076, 0.164489986374778, 0.164755732544751, 0.165022565966972,
0.165290491558336, 0.165559514265867, 0.165829639066933, 0.166100870969459,
0.166373215012143, 0.166646676264676, 0.166921259827962, 0.167196970834337,
0.167473814447798, 0.167751795864226, 0.16803092031161, 0.168311193050283,
0.16859261937315, 0.168875204605922, 0.169158954107351, 0.169443873269469,
0.169729967517823, 0.170017242311723, 0.17030570314448, 0.170595355543656,
0.170886205071306, 0.171178257324233, 0.171471517934237, 0.171765992568371,
0.172061686929194, 0.172358606755035, 0.172656757820246, 0.172956145935471,
0.173256776947909, 0.17355865674158, 0.173861791237597, 0.174166186394438,
0.174471848208216, 0.174778782712961, 0.175086995980898, 0.175396494122726,
0.175707283287904, 0.176019369664935, 0.17633275948166, 0.176647459005543,
0.17696347454397, 0.177280812444543, 0.177599479095379, 0.177919480925412,
0.178240824404697, 0.178563516044721, 0.178887562398705, 0.179212970061922,
0.17953974567201, 0.179867895909293, 0.180197427497096, 0.180528347202073,
0.180860661834532, 0.181194378248764, 0.181529503343377, 0.181866044061627,
0.18220400739176, 0.182543400367351, 0.18288423006765, 0.183226503617925,
0.183570228189819, 0.183915411001696, 0.184262059319004, 0.184610180454628,
0.184959781769258, 0.185310870671757, 0.185663454619521, 0.186017541118863,
0.18637313772538, 0.186730252044341, 0.187088891731061, 0.187449064491294,
0.187810778081621, 0.188174040309841, 0.18853885903537, 0.188905242169644,
0.189273197676518, 0.189642733572677, 0.190013857928047, 0.19038657886621,
0.190760904564824, 0.191136843256045, 0.191514403226953, 0.191893592819983,
0.192274420433363, 0.192656894521548, 0.193041023595664, 0.193426816223955,
0.193814281032235, 0.194203426704341, 0.194594261982594, 0.19498679566826,
0.195381036622021, 0.195776993764442, 0.196174676076453, 0.196574092599828,
0.196975252437666, 0.197378164754889, 0.197782838778727, 0.198189283799226,
0.198597509169745, 0.199007524307466, 0.199419338693909, 0.19983296187545,
0.20024840346384, 0.200665673136737, 0.201084780638235, 0.201505735779406,
0.201928548438839, 0.202353228563188, 0.202779786167727, 0.20320823133691,
0.203638574224928, 0.204070825056284, 0.204504994126367, 0.204941091802027,
0.205379128522166, 0.205819114798326, 0.206261061215286, 0.206704978431663,
0.207150877180523, 0.207598768269993, 0.208048662583881, 0.208500571082301,
0.208954504802308, 0.20941047485853, 0.209868492443818, 0.210328568829893,
0.210790715368003, 0.211254943489586, 0.211721264706939, 0.212189690613896,
0.212660232886506, 0.213132903283727, 0.213607713648118, 0.214084675906544,
0.214563802070883, 0.215045104238746, 0.215528594594196, 0.216014285408481,
0.216502189040772, 0.216992317938908, 0.217484684640145, 0.217979301771921,
0.218476182052619, 0.218975338292343, 0.219476783393702, 0.219980530352596,
0.220486592259021, 0.220994982297869, 0.221505713749742, 0.222018799991779,
0.222534254498484, 0.223052090842561, 0.223572322695767, 0.224094963829763,
0.224620028116982, 0.225147529531498, 0.22567748214991, 0.226209900152233,
0.226744797822793, 0.227282189551141, 0.227822089832971, 0.22836451327104,
0.228909474576113, 0.229456988567903, 0.230007070176029, 0.230559734440981,
0.231114996515097, 0.231672871663545, 0.232233375265318, 0.232796522814244,
0.233362329919996, 0.233930812309122, 0.234501985826082, 0.23507586643429,
0.23565247021718, 0.236231813379268, 0.236813912247239, 0.23739878327103,
0.23798644302494, 0.238576908208741, 0.239170195648803, 0.239766322299235,
0.240365305243027, 0.24096716169322, 0.241571908994073, 0.242179564622251,
0.242790146188023, 0.243403671436474, 0.244020158248724, 0.244639624643169,
0.245262088776728, 0.245887568946107, 0.246516083589072, 0.24714765128574,
0.247782290759884, 0.248420020880245, 0.249060860661866, 0.24970482926744,
0.25035194600866, 0.251002230347604, 0.251655701898113, 0.252312380427204,
0.252972285856481, 0.253635438263571, 0.254301857883574, 0.254971565110527,
0.255644580498884, 0.256320924765013, 0.257000618788707, 0.257683683614715,
0.258370140454285, 0.259060010686729, 0.259753315861001, 0.260450077697291,
0.261150318088643, 0.261854059102583, 0.262561322982772, 0.263272132150668,
0.263986509207217, 0.264704476934552, 0.265426058297719, 0.26615127644642,
0.266880154716771, 0.267612716633081, 0.268348985909659, 0.269088986452625,
0.269832742361758, 0.270580277932351, 0.271331617657098, 0.272086786227989,
0.27284580853824, 0.273608709684234, 0.27437551496749, 0.275146249896651,
0.275920940189494, 0.276699611774965, 0.277482290795235, 0.27826900360778,
0.279059776787482, 0.279854637128761, 0.28065361164772, 0.281456727584324,
0.2822640124046, 0.283075493802859, 0.283891199703951, 0.284711158265537,
0.285535397880392, 0.286363947178735, 0.287196835030582, 0.288034090548129,
0.28887574308816, 0.289721822254486, 0.290572357900409, 0.291427380131215,
0.292286919306696, 0.293151006043704, 0.29401967121873, 0.294892945970514,
0.295770861702688, 0.296653450086448, 0.297540743063257, 0.298432772847579,
0.299329571929646, 0.300231173078257, 0.301137609343611, 0.302048914060171,
0.302965120849563, 0.303886263623507, 0.30481237658679, 0.305743494240263,
0.306679651383881, 0.307620883119779, 0.308567224855379, 0.30951871230654,
0.310475381500742, 0.311437268780311, 0.312404410805677, 0.313376844558676,
0.314354607345891, 0.31533773680203, 0.316326270893349, 0.31732024792111,
0.318319706525089, 0.319324685687116, 0.32033522473467, 0.321351363344506,
0.322373141546331, 0.323400599726529, 0.324433778631921, 0.32547271937358,
0.326517463430689, 0.327568052654445, 0.328624529272012, 0.329686935890525,
0.330755315501134, 0.331829711483112, 0.332910167608, 0.333996728043813,
0.335089437359289, 0.3361883405282, 0.337293482933706, 0.338404910372776,
0.339522669060651, 0.340646805635367, 0.34177736716234, 0.342914401139002,
0.344057955499495, 0.345208078619425, 0.346364819320679, 0.347528226876294,
0.3486983510154, 0.34987524192821, 0.351058950271085, 0.352249527171659,
0.353447024234028, 0.354651493544003, 0.355862987674435, 0.357081559690603,
0.358307263155673, 0.359540152136224, 0.360780281207853, 0.362027705460834,
0.363282480505872, 0.36454466247991, 0.36581430805203, 0.367091474429409,
0.368376219363373, 0.369668601155511, 0.370968678663882, 0.372276511309294,
0.373592159081667, 0.374915682546477, 0.37624714285129, 0.377586601732372,
0.378934121521393, 0.380289765152215, 0.381653596167768, 0.38302567872702,
0.384406077612035, 0.385794858235125, 0.387192086646097, 0.388597829539595,
0.390012154262539, 0.391435128821664, 0.392866821891156, 0.39430730282039,
0.395756641641775, 0.3972149090787, 0.398682176553587, 0.400158516196047,
0.401644000851155, 0.403138704087829, 0.404642700207322, 0.40615606425183,
0.407678872013214, 0.409211200041844, 0.410753125655557, 0.41230472694874,
0.413866082801535, 0.415437272889168, 0.417018377691408, 0.418609478502151,
0.420210657439137, 0.421821997453802, 0.423443582341258, 0.425075496750418,
0.426717826194254, 0.428370657060202, 0.4300340766207, 0.431708173043885,
0.433393035404428, 0.435088753694524, 0.436795418835027, 0.438513122686754,
0.440241958061929, 0.4419820187358, 0.44373339945841, 0.445496195966538,
0.447270504995803, 0.449056424292939, 0.450854052628244, 0.452663489808202,
0.454484836688283, 0.456318195185927, 0.458163668293704, 0.460021360092671,
0.461891375765908, 0.463773821612251, 0.465668805060223, 0.467576434682156,
0.469496820208524, 0.471430072542472, 0.473376303774557, 0.475335627197701,
0.477308157322358, 0.4792940098919, 0.48129330189822, 0.483306151597566,
0.4853326785266, 0.487373003518694, 0.489427248720454, 0.491495537608494,
0.493577995006444, 0.495674747102214, 0.497785921465505, 0.499911647065577,
0.502052054289276, 0.504207274959328, 0.506377442352901, 0.508562691220433,
0.510763157804749, 0.51297897986045, 0.515210296673594, 0.517457249081665,
0.519719979493837, 0.521998631911548, 0.524293351949361, 0.526604286856157,
0.528931585536629, 0.531275398573102, 0.533635878247678, 0.536013178564717,
0.538407455273648, 0.540818865892126, 0.54324756972954, 0.545693727910873,
0.548157503400918, 0.550639061028867, 0.553138567513267, 0.555656191487358,
0.558192103524792, 0.560746476165743, 0.563319483943419, 0.565911303410975,
0.568522113168835, 0.571152093892437, 0.573801428360398, 0.576470301483111,
0.579158900331789, 0.581867414167945, 0.584596034473331, 0.587344954980342,
0.590114371702885, 0.592904482967725, 0.595715489446323, 0.59854759418716,
0.601401002648568, 0.604275922732072, 0.607172564816249, 0.610091141791118,
0.613031869093063, 0.615994964740309, 0.618980649368945, 0.621989146269524,
0.625020681424225, 0.62807548354461, 0.63115378410997, 0.634255817406277,
0.637381820565754, 0.640532033607065, 0.64370669947615, 0.646906064087698,
0.650130376367288, 0.653379888294188, 0.656654854944852, 0.659955534537093,
0.663282188474974, 0.666635081394407, 0.670014481209488, 0.673420659159574,
0.676853889857108, 0.680314451336222, 0.683802625102113, 0.68731869618122,
0.690862953172205, 0.694435688297756, 0.698037197457236, 0.70166778028017,
0.705327740180606, 0.709017384412357, 0.712737024125137, 0.716486974421608,
0.720267554415357, 0.724079087289815, 0.727921900358139, 0.731796325124065,
0.73570269734376, 0.739641357088679, 0.743612648809459, 0.747616921400851,
0.751654528267718, 0.755725827392119, 0.75983118140149, 0.76397095763795,
0.768145528228741, 0.772355270157834, 0.776600565338707, 0.780881800688335,
0.785199368202383, 0.78955366503166, 0.793945093559819, 0.798374061482355,
0.802840981886904, 0.807346273334868, 0.811890359944402, 0.816473671474767,
0.821096643412089, 0.825759717056535, 0.830463339610946, 0.835207964270926,
0.839994050316449, 0.844822063204971, 0.849692474666098, 0.854605762797835,
0.85956241216442, 0.864562913895808, 0.869607765788795, 0.874697472409829,
0.879832545199546, 0.885013502579025, 0.890240870057837, 0.895515180343878,
0.900836973455035, 0.906206796832719, 0.911625205457281, 0.917092761965356,
0.922610036769158, 0.928177608177759, 0.933796062520393, 0.939465994271806,
0.945188006179693, 0.950962709394249, 0.956790723599879, 0.962672677149092,
0.968609207198612, 0.974600959847752, 0.98064859027908, 0.986752762901407,
0.992914151495149, 0.999133439360083, 1.00541131946554, 1.0117484946031,
1.01814567754173, 1.02460359118558, 1.03112296873426, 1.03770455384584,
1.04434910080242, 1.05105737467852, 1.05783015151208, 1.06466821847839,
1.07157237406671, 1.07854342825986, 1.08558220271664, 1.09268953095722,
1.09986625855153, 1.10711324331065, 1.11443135548128, 1.12182147794325,
1.12928450641032, 1.13682134963396, 1.14443292961054, 1.15212018179164,
1.15988405529777, 1.16772551313532, 1.17564553241696, 1.18364510458546,
1.19172523564088, 1.19988694637132, 1.20813127258717, 1.21645926535893,
1.22487199125854, 1.23337053260447, 1.24195598771034, 1.25062947113729,
1.25939211395004, 1.2682450639767, 1.27718948607235, 1.28622656238638,
1.29535749263372, 1.3045834943698, 1.31390580326946, 1.32332567340966,
1.33284437755611, 1.34246320745381, 1.35218347412142, 1.36200650814963,
1.37193366000337, 1.38196630032797, 1.39210582025918, 1.40235363173713,
1.41271116782414, 1.4231798830264, 1.43376125361948, 1.44445677797766,
1.45526797690703, 1.46619639398233, 1.47724359588748, 1.48841117275974,
1.49970073853747, 1.51111393131137, 1.5226524136792, 1.53431787310381,
1.54611202227448, 1.55803659947138, 1.57009336893313, 1.58228412122724,
1.59461067362338, 1.60707487046933, 1.61967858356934, 1.63242371256497,
1.64531218531793, 1.65834595829495, 1.67152701695441, 1.68485737613442,
1.69833908044218, 1.71197420464445, 1.72576485405856, 1.73971316494402,
1.7538213048941, 1.76809147322728, 1.78252590137798, 1.79712685328638,
1.8118966257868, 1.82683754899417, 1.84195198668824, 1.85724233669495,
1.87271103126437, 1.88836053744482, 1.90419335745236, 1.92021202903522,
1.93641912583231, 1.95281725772524, 1.96940907118308, 1.9861972495989,
2.00318451361754, 2.02037362145344, 2.03776736919778, 2.0553685911138,
2.07318015991939, 2.09120498705573, 2.10944602294091, 2.12790625720719,
2.14658871892075, 2.16549647678244, 2.18463263930821, 2.20400035498756,
2.22360281241868, 2.24344324041827, 2.26352490810464, 2.28385112495197,
2.30442524081398, 2.32525064591489, 2.34633077080554, 2.36766908628253,
2.38926910326789, 2.41113437264693, 2.43326848506172, 2.45567507065736,
2.47835779877839, 2.50132037761223, 2.52456655377673, 2.54810011184839,
2.57192487382806, 2.59604469854048, 2.62046348096394, 2.64518515148636,
2.67021367508358, 2.69555305041579, 2.72120730883764, 2.74718051331758,
2.77347675726154, 2.80010016323613, 2.82705488158604, 2.85434508894054,
2.88197498660324, 2.90994879881949, 2.93827077091539, 2.96694516730204,
2.99597626933882, 3.02536837304872, 3.05512578667895, 3.08525282809956,
3.1157538220327, 3.1466330971048, 3.17789498271367, 3.20954380570253,
3.24158388683228, 3.27401953704356, 3.30685505349945, 3.34009471539983,
3.37374277955779, 3.40780347572854, 3.44228100168088, 3.47717951800111,
3.51250314261899, 3.54825594504538, 3.58444194031052, 3.62106508259244,
3.65812925852402, 3.69563828016792, 3.73359587764766, 3.77200569142381,
3.81087126420363, 3.85019603247277, 3.88998331763749, 3.93023631676615,
3.9709580929185, 4.01215156505172, 4.05381949749217, 4.09596448896233,
4.13858896115228, 4.18169514682602, 4.225285077453, 4.26936057035584,
4.31392321536612, 4.35897436098048, 4.40451510001032, 4.45054625471939,
4.49706836144439, 4.54408165469509, 4.59158605073174, 4.63958113061874,
4.68806612275574, 4.73703988488826, 4.78650088560256, 4.83644718531116,
4.88687641673778, 4.93778576491282, 4.9891719466933, 5.04103118982387,
5.09335921155849, 5.14615119686566, 5.19940177624365, 5.25310500317552,
5.30725433125797, 5.36184259104187, 5.41686196662666, 5.47230397205558,
5.5281594275631, 5.58441843573103, 5.64107035761498, 5.69810378890798,
5.75550653621385, 5.81326559350816, 5.87136711887098, 5.92979641158084,
5.98853788966604, 6.04757506801486, 6.10689053715278, 6.16646594280064,
6.22628196633371, 6.28631830626767, 6.34655366090301, 6.40696571226526,
6.46753111148334, 6.52822546575354, 6.58902332704112, 6.6498981826754,
6.71082244799802, 6.7717674612266, 6.83270348069849, 6.89359968466034,
6.95442417377007, 7.01514397647684, 7.0757250574436, 7.13613232917356,
7.19632966699837, 7.25627992758037, 7.31594497107456, 7.37528568708809,
7.43426202456508, 7.49283302571387, 7.55095686408033, 7.60859088685726,
7.66569166150283, 7.72221502672414, 7.77811614786189, 7.83334957669142,
7.88786931563279, 7.94162888633836, 7.99458140260103, 8.04667964749941,
8.09787615466862, 8.14812329355627, 8.19737335849394, 8.2455786613843,
8.29269162777338, 8.33866489604749, 8.38345141946338, 8.42700457069126,
8.46927824852053, 8.51022698635093, 8.54980606206488, 8.58797160885252,
8.62468072653814, 8.65989159293669, 8.69356357475138, 8.7256573375091,
8.75613495401908, 8.7849600108323, 8.8120977121755, 8.83751498083311,
8.86118055545461, 8.88306508377275, 8.90314121123023, 8.92138366452907,
8.93776932963719, 8.95227732381165, 8.96488906122628, 8.97558831182403,
8.98436125304979, 8.99119651415869, 8.99608521283661, 8.99902098391393
)