~ubuntu-branches/ubuntu/natty/pd-zexy/natty

« back to all changes in this revision

Viewing changes to src/prime.c

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard, IOhannes m zmölnig, Jonas Smedegaard
  • Date: 2010-08-20 12:17:41 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100820121741-4kxozn8b9rhee9fr
Tags: 2.2.3-1
* New upstream version

[ IOhannes m zmölnig ]
* Adopt package, on behalf of Multimedia Team.
  Closes: #546964
* Simply debian/rules with CDBS, and don't unconditionally strip
  binaries.
  Closes: #437763
* Install into /usr/lib/pd/extra/zexy/. Document usage in REAME.Debian
  and warn about change in NEWS.
* git'ify package. Add Vcs-* stanzas to control file.
* Use dpkg source format 3.0 (quilt). Drop build-dependency on quilt.

[ Jonas Smedegaard ]
* Enable CDBS copyright-check routine.
* Add copyright and licensing header to debian/rules.
* Add myself as uploader.
* Rewrite debian/copyright using rev. 135 of draft DEP5 format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************
 
2
 *
 
3
 * zexy - implementation file
 
4
 *
 
5
 * copyleft (c) IOhannes m zm�lnig
 
6
 *
 
7
 *   1999:forum::f�r::uml�ute:2004
 
8
 *
 
9
 *   institute of electronic music and acoustics (iem)
 
10
 *
 
11
 ******************************************************
 
12
 *
 
13
 * license: GNU General Public License v.2
 
14
 *
 
15
 ******************************************************/
 
16
 
 
17
/* get the n-th prime number */
 
18
 
 
19
#include "zexy.h"
 
20
 
 
21
 
 
22
static t_class *prime_class;
 
23
 
 
24
typedef struct _prime {
 
25
  t_object  x_obj;
 
26
} t_prime;
 
27
 
 
28
 
 
29
static void prime_float(t_prime *x, t_float f)
 
30
{
 
31
 
 
32
  unsigned int i=f;
 
33
  unsigned int max_divisor;
 
34
  unsigned int divisor=1;
 
35
 
 
36
  if (f<2){
 
37
    outlet_float(x->x_obj.ob_outlet, 0.0);
 
38
    return;
 
39
  }
 
40
 
 
41
  if (!(i%2)){
 
42
    outlet_float(x->x_obj.ob_outlet, (t_float)(i==2));
 
43
    return;
 
44
  }
 
45
 
 
46
  max_divisor = sqrt(f)+1;
 
47
 
 
48
  while ((divisor+=2)<max_divisor)
 
49
    if (!(i%divisor)) {
 
50
      outlet_float(x->x_obj.ob_outlet, 0.0);
 
51
      return;
 
52
    }
 
53
 
 
54
  outlet_float(x->x_obj.ob_outlet, 1.0);
 
55
}
 
56
 
 
57
static void *prime_new(void)
 
58
{
 
59
  t_prime *x = (t_prime *)pd_new(prime_class);
 
60
 
 
61
  outlet_new(&x->x_obj, &s_float);
 
62
 
 
63
  return (x);
 
64
}
 
65
 
 
66
static void prime_help(t_prime*x)
 
67
{
 
68
  post("\n%c prime\t\t:: test whether a given number is prime", HEARTSYMBOL);
 
69
}
 
70
 
 
71
 
 
72
void prime_setup(void) {
 
73
  prime_class = class_new(gensym("prime"),
 
74
                          (t_newmethod)prime_new,
 
75
                          0, sizeof(t_prime),
 
76
                          CLASS_DEFAULT, 0);
 
77
 
 
78
  class_addfloat(prime_class, prime_float);
 
79
  class_addmethod(prime_class, (t_method)prime_help, gensym("help"), A_NULL);
 
80
  zexy_register("prime");
 
81
}