/* Modnumlib Scicos interfacing function * Copyright (C) 2009 Alan Layec * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ /* imodulob Scicos integer modulob function block * Type 2 simulation function - scilab-2.6&2.7&3.0 * IRCOM GROUP - Author : A.Layec */ /* REVISION HISTORY : * $Log$ */ #include "machine.h" /* Cette fonction de simulation propose de réaliser la fonction * modulo rencontrée dans les systèmes numériques traitant les opérations * sur entier en code complément à 2. * entrées régulières : u[0..nu-1] * sorties régulières : y[0..nu-1] = mod[u[0..nu-1]] * paramètres entiers : ipar[0..nu-1] : nombre de bits des mots entiers. * * Rmq : l'entrée de type double est tronquée à sa valeur entière. * la sortie est tjs positive */ /*Prototype*/ void imodulob(flag,nevprt,t,xd,x,nx,z,nz,tvec,ntvec,rpar,nrpar, ipar,nipar,inptr,insz,nin,outptr,outsz,nout) integer *flag,*nevprt,*nx,*nz,*ntvec,*nrpar,ipar[],*nipar,insz[],*nin,outsz[],*nout; double x[],xd[],z[],tvec[],rpar[]; double *inptr[],*outptr[],*t; { /*Déclaration des variables*/ int i,nu; double *y; double *u; long ent; /*Déclaration d'un entier de type long long int*/ /*Récupération des adresses des ports réguliers*/ y=(double *)outptr[0]; u=(double *)inptr[0]; /*Récupération de la taille du port d'entrée*/ nu=insz[0]; for(i=0;i<nu;i++) { /*Récupération de la valeur d'entrée*/ ent = (long) u[i]; /*Conversion en nombre entier non signé*/ ent &= (2<<(ipar[i]-1)) - 1; /*Place nombre converti dans le registre de sortie*/ y[i] = ent; } }