# FW: [PATCH] Bug #24064: Standard deviation

- Thread: https://externals.io/message/7682
- Original archive: https://news-web.php.net/php.internals/7682
- Started by Paul Hudson on 2004-02-10T00:53:16+00:00
- Messages: 6
- 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

---

## #7682 — Paul Hudson — 2004-02-10T00:53:16+00:00

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

Er, either the php-internals MARC archive doesn't show all attachments, or
my diff file got stripped en route for not having a .txt extension.  I've
attached it again, just to make sure.


Paul
--

-----Original Message-----
From: Paul Hudson [mailto:webjedi@hudzilla.eclipse.co.uk] 
Sent: 10 February 2004 00:30
To: 'internals@lists.php.net'
Subject: [PATCH] Bug #24064: Standard deviation

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.

---

## #7685 — Jani Taskinen — 2004-02-10T03:15:26+00:00

URL: https://externals.io/message/7682#7685 · In reply to: #7682

Quickly checked out the patch and first thing to catch my eye
    was the use of '//' comments. That's a big no-no. (this is not C++)
    Please read the CODING_STANDARDS couple of times. :)
    
    (Use of these C++ comments causes compile failure with some compilers)
    
    --Jani
           



>Er, either the php-internals MARC archive doesn't show all attachments, or
>my diff file got stripped en route for not having a .txt extension.  I've
>attached it again, just to make sure.
>
>
>Paul
>--
>
>-----Original Message-----
>From: Paul Hudson [mailto:webjedi@hudzilla.eclipse.co.uk] 
>Sent: 10 February 2004 00:30
>To: 'internals@lists.php.net'
>Subject: [PATCH] Bug #24064: Standard deviation
>
>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.

---

## #7686 — Andrey Hristov — 2004-02-10T08:15:06+00:00

URL: https://externals.io/message/7682#7686 · In reply to: #7682

Hi, 
as Derick stated 2 days ago, the problem is not in the extension but in the 
MIME header. The attachment must be text/plain. 
 
Andrey 
 
Quoting Paul Hudson <webjedi@hudzilla.eclipse.co.uk>: 
 
> Er, either the php-internals MARC archive doesn't show all attachments, or 
> my diff file got stripped en route for not having a .txt extension.  I've 
> attached it again, just to make sure. 
>  
>  
> Paul 
> -- 
>  
> -----Original Message----- 
> From: Paul Hudson [mailto:webjedi@hudzilla.eclipse.co.uk]  
> Sent: 10 February 2004 00:30 
> To: 'internals@lists.php.net' 
> Subject: [PATCH] Bug #24064: Standard deviation 
>  
> 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.

---

## #7687 — Andrey Hristov — 2004-02-10T08:30:23+00:00

URL: https://externals.io/message/7682#7687 · In reply to: #7682

Hi Paul, 
may you compile your PHP binary with --enable-debug and after that run your 
sample scrit for once. See if there are leaks. 
 
Andrey 
 
Quoting Paul Hudson <webjedi@hudzilla.eclipse.co.uk>: 
 
> Er, either the php-internals MARC archive doesn't show all attachments, or 
> my diff file got stripped en route for not having a .txt extension.  I've 
> attached it again, just to make sure. 
>  
>  
> Paul 
> -- 
>  
> -----Original Message----- 
> From: Paul Hudson [mailto:webjedi@hudzilla.eclipse.co.uk]  
> Sent: 10 February 2004 00:30 
> To: 'internals@lists.php.net' 
> Subject: [PATCH] Bug #24064: Standard deviation 
>  
> 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.

---

## #7697 — Paul Hudson — 2004-02-10T12:33:15+00:00

URL: https://externals.io/message/7682#7697 · In reply to: #7687

Andrey, 
 
I compiled with "--enable-debug" already (but did it 
again just to make sure).  It works fine, with no report of 
leaks.  Did I miss something? 
 
Jani: You're absolutely right about the comments; sorry 
about that! 
 
Otherwise, is the patch OK to be committed? 
 
 
Paul 
-- 
 
Quoting Andrey Hristov <php@hristov.com>: 
 
> Hi Paul,  
> may you compile your PHP binary with 
> --enable-debug and after that run your  
> sample scrit for once. See if there are leaks. 
>  
>   
> Andrey  
>   
> Quoting Paul Hudson 
> <webjedi@hudzilla.eclipse.co.uk>:  
>   
> > […]
> doesn't show all attachments, or  
> > […]
> having a .txt extension.  I've  
> > […]
> [mailto:webjedi@hudzilla.eclipse.co.uk]   
> > […]
> deviation  
> > […]
> requests a standard deviation  
> > […]
> could implement this in 10  
> > […]
> is still Open so I figured I  
> > […]
> and/or places where it could  
> > […]
> might be able to help with  
> > […]
> the function array_std_dev(),  
> > […]
> deviation method.  
> > […]
> is calculated like this:  
> > […]
> using an extra array to buffer the  
> > […]
> see how the array stuff  
> > […]
> couldn't figure out why - can  
> > […]
> attached the offending code  
> > […]
> appreciate it if you would CC  
> > […]

---

## #7700 — Ard Biesheuvel — 2004-02-10T15:27:51+00:00

URL: https://externals.io/message/7682#7700 · In reply to: #7682

Hi Paul,

Why are you comparing, copying and converting each array element twice ? 
There should be a more elegant way to do this.

-- 
Ard
