Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Passing values from structure arrays to a generic geometrical mean function Date: Sat, 28 Jan 2017 19:00:02 -0800 Organization: None to speak of Lines: 31 Message-ID: References: <8abfc054-e7c3-498c-a7b4-8e7471f57ac6@googlegroups.com> <0a48658d-968a-4ddf-8c3e-5a856e298ec1@googlegroups.com> <87lgtwxxjp.fsf@bsb.me.uk> <50df88d5-9db9-401b-bf2d-bf1846d68b7b@googlegroups.com> <87wpdgvzmp.fsf@bsb.me.uk> <522dd411-1a86-49fb-8df7-a1384f3c5da8@googlegroups.com> <4f8b2e49-6a8b-fb05-e35b-d21fb00f6779@verizon.net> <899963c8-4716-422b-93c9-59e98c91a160@googlegroups.com> <43aa17b1-6286-8ec5-c9d7-fe59d88c1688@verizon.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="0fd733d9f8cc5cb46740a4e887498fc9"; logging-data="13292"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ptW/JblJdZe+5rF3p7cPf" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:/5b97hF4X/zK6g/yWU6BTap+Uyo= sha1:SJltMK/aB86FR1jISmnm3xSxEMk= Xref: csiph.com comp.lang.c:102665 "James R. Kuyper" writes: > On 01/28/2017 01:38 PM, Alla _ wrote: [...] >> No no, you can't use this standard geo mean formula for negative >> numbers, which are not in the range between zero and one. > > Why not? The geometric mean of numbers, some of which are negative, is > perfectly well defined: the formula (a1*a2*...*aN)^(1/N) doesn't care > whether a2 is negative. If the number of negative values is odd, the > result is imaginary - but under precisely those circumstances, there is > no real value that matches the input data. If any meaning can be > attached to an imaginary value (which is more common in the sciences > than in economics), that meaning is probably correct. Otherwise, either > the data is wrong, or the model that calls for you to calculate the > geometric mean is wrong. True, but I suspect that in this context *any* negative values would be an error. For example, if you have (2, -3, 4, -5, 6), the geometric mean is approximately 3.73 (the same as the geometric mean of (2, 3, 4, 5, 6) -- but the presence of negative data likely indicates an error whether the number of negative values is even or odd. If your input data doesn't make sense in context, you should check and report the error before trying to compute a result. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"