summaryrefslogtreecommitdiff
path: root/modules/integer/src/c/genrdiv.c
blob: 912a6de44f4a40231329bc0e3946b0cfbc1fe3ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) INRIA -
*
* 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.1-en.txt
*
*/

#include "genrdiv.h"

#define RDIV(Type) {\
Type *A = 0;\
Type *B = 0;\
Type *R = 0;\
    A=(Type *)a;\
    --A;\
    B=(Type *)b;\
    --B;\
    R=(Type *)r;\
    --R;\
    jr = 1;jb = 1;ja = 1;\
    *ierr = 0;\
    if (*ia == 0) {\
	for (k = 1; k <= i1; ++k) {\
	    if (B[jb] == 0) {*ierr = k;return 0;}\
	    R[jr] = A[ja] / B[jb];\
	    jr += *ir;jb += *ib;\
	}\
    }\
    else if (*ib == 0) {\
	if (B[jb] == 0) {*ierr = 1;return 0;}\
	for (k = 1; k <= i1; ++k) {\
	    R[jr] = A[ja] / B[jb];\
	    jr += *ir;ja += *ia;\
	}\
    }\
    else {\
	for (k = 1; k <= i1; ++k) {\
	    if (B[jb] == 0) {*ierr = k;return 0;}\
	    R[jr] = A[ja] / B[jb];\
	    jr += *ir;jb += *ib;ja += *ia;\
	}\
    }\
}

int C2F(genrdiv)(int *typ, int *a, int *ia, int *b, int *ib, int *r, int *ir, int *n, int *ierr)
{
    int i1 = 0;
    static int k = 0, jb = 0, ja = 0, jr = 0;

    i1 = *n;
    switch (*typ)
    {
        case 1:
            RDIV(integer1);
            break;
        case 2:
            RDIV(integer2);
            break;
        case 4:
            RDIV(int) ;
            break;
        case 11:
            RDIV(unsigned char);
            break;
        case 12:
            RDIV(unsigned short);
            break;
        case 14:
            RDIV(unsigned int);
            break;
    }
    return 0;
}