# [PATCH] Bug #24064: Standard deviation

- Thread: https://externals.io/message/7681
- Original archive: https://news-web.php.net/php.internals/7681
- Started by Paul Hudson on 2004-02-10T00:30:02+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #7681 — Paul Hudson — 2004-02-10T00:30:02+00:00

URL: https://externals.io/message/7681#7681

Hi there,

Bug #24064 (submitted by tularis@php.net) requests a standard deviation
function for PHP.  I realise that any of you could implement this in 10
minutes, but according to the bug database it is still Open so I figured I
would give it a try myself!

There are probably a dozen errors in the code and/or places where it could
be better optimised, but I'm hoping one of you might be able to help with
that.  So, the attached diff file implements the function array_std_dev(),
to calculate standard deviation using the deviation method.

With the function in place, standard deviation is calculated like this:

<?php
  $scores = array(18,5,7,18,3,2,10);
  print array_std_dev($score);
  // prints 6.6833125519211
?>

My first attempt at implementing this was using an extra array to buffer the
deviations - this was more out of curiosity to see how the array stuff
works.  Sadly, it caused PHP to segfault and I couldn't figure out why - can
any of you help me spot the brain fart?  (I've attached the offending code
in bad_stddev_code.txt)

Yours,


Paul

PS: I'm not on the internals list, so I would appreciate it if you would CC
me on your reply.
