summaryrefslogtreecommitdiff
path: root/src/c/elementaryFunctions/discrete_mathematics
diff options
context:
space:
mode:
Diffstat (limited to 'src/c/elementaryFunctions/discrete_mathematics')
-rw-r--r--src/c/elementaryFunctions/discrete_mathematics/factor/dfactors.c39
-rw-r--r--src/c/elementaryFunctions/discrete_mathematics/factor/sfactors.c39
-rw-r--r--src/c/elementaryFunctions/discrete_mathematics/factorial/dfactoriala.c23
-rw-r--r--src/c/elementaryFunctions/discrete_mathematics/factorial/dfactorials.c35
-rw-r--r--src/c/elementaryFunctions/discrete_mathematics/factorial/sfactoriala.c23
-rw-r--r--src/c/elementaryFunctions/discrete_mathematics/factorial/sfactorials.c34
-rw-r--r--src/c/elementaryFunctions/discrete_mathematics/primes/dprimess.c35
-rw-r--r--src/c/elementaryFunctions/discrete_mathematics/primes/sprimess.c35
8 files changed, 263 insertions, 0 deletions
diff --git a/src/c/elementaryFunctions/discrete_mathematics/factor/dfactors.c b/src/c/elementaryFunctions/discrete_mathematics/factor/dfactors.c
new file mode 100644
index 0000000..9ac76b5
--- /dev/null
+++ b/src/c/elementaryFunctions/discrete_mathematics/factor/dfactors.c
@@ -0,0 +1,39 @@
+/* Copyright (C) 2017 - IIT Bombay - FOSSEE
+
+ This file must be used under the terms of the CeCILL.
+ This source file is licensed as described in the file COPYING, which
+ you should have received as part of this distribution. The terms
+ are also available at
+ http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ Organization: FOSSEE, IIT Bombay
+ Author: Shamik Guha
+ Email: toolbox@scilab.in
+*/
+# include <stdio.h>
+# include <math.h>
+
+void dfactors(double in,double* out)
+{
+ int i=0,k=0;
+ int n=(int)in;
+ while (n%2 == 0)
+ {
+ out[k++]=2;
+ n = n/2;
+ }
+
+ for (i = 3; i <= (int)sqrt((double)n); i = i+2)
+ {
+ while (n%i == 0)
+ {
+ out[k++]=i;
+ n = n/i;
+ }
+ }
+
+ if (n > 2)
+ {
+ out[k++]=n;
+ }
+}
+
diff --git a/src/c/elementaryFunctions/discrete_mathematics/factor/sfactors.c b/src/c/elementaryFunctions/discrete_mathematics/factor/sfactors.c
new file mode 100644
index 0000000..a2eed09
--- /dev/null
+++ b/src/c/elementaryFunctions/discrete_mathematics/factor/sfactors.c
@@ -0,0 +1,39 @@
+/* Copyright (C) 2017 - IIT Bombay - FOSSEE
+
+ This file must be used under the terms of the CeCILL.
+ This source file is licensed as described in the file COPYING, which
+ you should have received as part of this distribution. The terms
+ are also available at
+ http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ Organization: FOSSEE, IIT Bombay
+ Author: Shamik Guha
+ Email: toolbox@scilab.in
+*/
+# include <stdio.h>
+# include <math.h>
+
+void sfactors(float in,float* out)
+{
+ int i=0,k=0;
+ int n=(int)in;
+ while (n%2 == 0)
+ {
+ out[k++]=2;
+ n = n/2;
+ }
+
+ for (i = 3; i <= (int)sqrt((double)n); i = i+2)
+ {
+ while (n%i == 0)
+ {
+ out[k++]=i;
+ n = n/i;
+ }
+ }
+
+ if (n > 2)
+ {
+ out[k++]=n;
+ }
+}
+
diff --git a/src/c/elementaryFunctions/discrete_mathematics/factorial/dfactoriala.c b/src/c/elementaryFunctions/discrete_mathematics/factorial/dfactoriala.c
new file mode 100644
index 0000000..68a118b
--- /dev/null
+++ b/src/c/elementaryFunctions/discrete_mathematics/factorial/dfactoriala.c
@@ -0,0 +1,23 @@
+/* Copyright (C) 2017 - IIT Bombay - FOSSEE
+
+ This file must be used under the terms of the CeCILL.
+ This source file is licensed as described in the file COPYING, which
+ you should have received as part of this distribution. The terms
+ are also available at
+ http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ Organization: FOSSEE, IIT Bombay
+ Author: Shamik Guha
+ Email: toolbox@scilab.in
+*/
+#include "factorial.h"
+#include <math.h>
+
+void dfactoriala(double* in,int size,double* out)
+{
+ int i=0;
+ for (i=0;i<size;i++)
+ {
+ out[i] = dfactorials(in[i]);
+ }
+}
+
diff --git a/src/c/elementaryFunctions/discrete_mathematics/factorial/dfactorials.c b/src/c/elementaryFunctions/discrete_mathematics/factorial/dfactorials.c
new file mode 100644
index 0000000..354eb6a
--- /dev/null
+++ b/src/c/elementaryFunctions/discrete_mathematics/factorial/dfactorials.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 2017 - IIT Bombay - FOSSEE
+
+ This file must be used under the terms of the CeCILL.
+ This source file is licensed as described in the file COPYING, which
+ you should have received as part of this distribution. The terms
+ are also available at
+ http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ Organization: FOSSEE, IIT Bombay
+ Author: Shamik Guha
+ Email: toolbox@scilab.in
+*/
+#include <stdio.h>
+#include <math.h>
+#include "factorial.h"
+
+double dfactorials(double in)
+{
+ int i,n;
+ long long int fact=1;
+ n=(int)in;
+ if (n < 0)
+ printf("Error! Factorial of a negative number doesn't exist.");
+ else if (n>170)
+ printf("Inf");
+ else
+ {
+ for(i=1; i<=n; i++)
+ {
+ fact=fact*i;
+ //printf("\n %lld",fact);
+ }
+ }
+
+ return fact;
+}
diff --git a/src/c/elementaryFunctions/discrete_mathematics/factorial/sfactoriala.c b/src/c/elementaryFunctions/discrete_mathematics/factorial/sfactoriala.c
new file mode 100644
index 0000000..14f46d8
--- /dev/null
+++ b/src/c/elementaryFunctions/discrete_mathematics/factorial/sfactoriala.c
@@ -0,0 +1,23 @@
+/* Copyright (C) 2017 - IIT Bombay - FOSSEE
+
+ This file must be used under the terms of the CeCILL.
+ This source file is licensed as described in the file COPYING, which
+ you should have received as part of this distribution. The terms
+ are also available at
+ http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ Organization: FOSSEE, IIT Bombay
+ Author: Shamik Guha
+ Email: toolbox@scilab.in
+*/
+#include "factorial.h"
+#include <math.h>
+
+void sfactoriala(float* in,int size,float* out)
+{
+ int i=0;
+ for (i=0;i<size;i++)
+ {
+ out[i] = dfactorials(in[i]);
+ }
+}
+
diff --git a/src/c/elementaryFunctions/discrete_mathematics/factorial/sfactorials.c b/src/c/elementaryFunctions/discrete_mathematics/factorial/sfactorials.c
new file mode 100644
index 0000000..e4f1017
--- /dev/null
+++ b/src/c/elementaryFunctions/discrete_mathematics/factorial/sfactorials.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 2017 - IIT Bombay - FOSSEE
+
+ This file must be used under the terms of the CeCILL.
+ This source file is licensed as described in the file COPYING, which
+ you should have received as part of this distribution. The terms
+ are also available at
+ http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ Organization: FOSSEE, IIT Bombay
+ Author: Shamik Guha
+ Email: toolbox@scilab.in
+*/
+#include <stdio.h>
+#include <math.h>
+#include "factorial.h"
+
+float sfactorials(float in)
+{
+ int i,n;
+ long long int fact=1;
+ n=(int)in;
+ if (n < 0)
+ printf("Error! Factorial of a negative number doesn't exist.");
+ else if(n>170)
+ printf("Inf");
+ else
+ {
+ for(i=1; i<=n; i++)
+ {
+ fact *= i;
+ }
+ }
+
+ return fact;
+}
diff --git a/src/c/elementaryFunctions/discrete_mathematics/primes/dprimess.c b/src/c/elementaryFunctions/discrete_mathematics/primes/dprimess.c
new file mode 100644
index 0000000..3aa0af4
--- /dev/null
+++ b/src/c/elementaryFunctions/discrete_mathematics/primes/dprimess.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 2017 - IIT Bombay - FOSSEE
+
+ This file must be used under the terms of the CeCILL.
+ This source file is licensed as described in the file COPYING, which
+ you should have received as part of this distribution. The terms
+ are also available at
+ http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ Organization: FOSSEE, IIT Bombay
+ Author: Shamik Guha
+ Email: toolbox@scilab.in
+*/
+#include<stdio.h>
+#include "primes.h"
+void dprimess(double in, double* out)
+{
+ int i=0,j=0,k=0,n=0,counter=0;
+ n=(int)in;
+ for(i=2;i<=n;i++)
+ {
+ counter=0;
+ for(j=2;j<i;j++)
+ {
+ if(i%j==0)
+ {
+ counter=1;
+ break;
+ }
+ }
+ if(counter==0)
+ {
+ out[k++]=i;
+
+ }
+ }
+}
diff --git a/src/c/elementaryFunctions/discrete_mathematics/primes/sprimess.c b/src/c/elementaryFunctions/discrete_mathematics/primes/sprimess.c
new file mode 100644
index 0000000..bff39d7
--- /dev/null
+++ b/src/c/elementaryFunctions/discrete_mathematics/primes/sprimess.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 2017 - IIT Bombay - FOSSEE
+
+ This file must be used under the terms of the CeCILL.
+ This source file is licensed as described in the file COPYING, which
+ you should have received as part of this distribution. The terms
+ are also available at
+ http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ Organization: FOSSEE, IIT Bombay
+ Author: Shamik Guha
+ Email: toolbox@scilab.in
+*/
+#include<stdio.h>
+#include "primes.h"
+void sprimess(float in, float* out)
+{
+ int i=0,j=0,k=0,n=0,counter=0;
+ n=(int)in;
+ for(i=2;i<=n;i++)
+ {
+ counter=0;
+ for(j=2;j<i;j++)
+ {
+ if(i%j==0)
+ {
+ counter=1;
+ break;
+ }
+ }
+ if(counter==0)
+ {
+ out[k]=i;
+ k++;
+ }
+ }
+}