1991-03-05 11:56:39 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Module: CARDINAL operations with overflow checking
|
|
|
|
* Author: Ceriel J.H. Jacobs
|
1994-06-24 14:02:31 +00:00
|
|
|
* Version: $Id$
|
1991-03-05 11:56:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef EM_WSIZE
|
|
|
|
#define EM_WSIZE _EM_WSIZE
|
|
|
|
#endif
|
|
|
|
#ifndef EM_LSIZE
|
|
|
|
#define EM_LSIZE _EM_LSIZE
|
|
|
|
#endif
|
|
|
|
|
2018-06-25 20:22:37 +00:00
|
|
|
#include "libm2.h"
|
1991-03-05 11:56:39 +00:00
|
|
|
#include <m2_traps.h>
|
|
|
|
|
2018-06-25 20:22:37 +00:00
|
|
|
#define MAXCARD ((unsigned)-1)
|
1991-03-05 11:56:39 +00:00
|
|
|
#if EM_WSIZE < EM_LSIZE
|
2018-06-25 20:22:37 +00:00
|
|
|
#define MAXLONGCARD ((unsigned long)-1L)
|
1991-03-05 11:56:39 +00:00
|
|
|
#endif
|
|
|
|
|
2018-06-25 20:22:37 +00:00
|
|
|
void adduchk(unsigned int a, unsigned int b)
|
1991-03-05 11:56:39 +00:00
|
|
|
{
|
2018-06-25 20:22:37 +00:00
|
|
|
if (MAXCARD - a < b)
|
|
|
|
TRP(M2_UOVFL);
|
1991-03-05 11:56:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if EM_WSIZE < EM_LSIZE
|
2018-06-25 20:22:37 +00:00
|
|
|
void addulchk(unsigned long a, unsigned long b)
|
1991-03-05 11:56:39 +00:00
|
|
|
{
|
2018-06-25 20:22:37 +00:00
|
|
|
if (MAXLONGCARD - a < b)
|
|
|
|
TRP(M2_UOVFL);
|
1991-03-05 11:56:39 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-06-25 20:22:37 +00:00
|
|
|
void muluchk(unsigned int a, unsigned int b)
|
1991-03-05 11:56:39 +00:00
|
|
|
{
|
2018-06-25 20:22:37 +00:00
|
|
|
if (a != 0 && MAXCARD / a < b)
|
|
|
|
TRP(M2_UOVFL);
|
1991-03-05 11:56:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if EM_WSIZE < EM_LSIZE
|
2018-06-25 20:22:37 +00:00
|
|
|
void mululchk(unsigned long a, unsigned long b)
|
1991-03-05 11:56:39 +00:00
|
|
|
{
|
2018-06-25 20:22:37 +00:00
|
|
|
if (a != 0 && MAXLONGCARD / a < b)
|
|
|
|
TRP(M2_UOVFL);
|
1991-03-05 11:56:39 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-06-25 20:22:37 +00:00
|
|
|
void subuchk(unsigned int a, unsigned int b)
|
1991-03-05 11:56:39 +00:00
|
|
|
{
|
2018-06-25 20:22:37 +00:00
|
|
|
if (b < a)
|
|
|
|
TRP(M2_UUVFL);
|
1991-03-05 11:56:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if EM_WSIZE < EM_LSIZE
|
2018-06-25 20:22:37 +00:00
|
|
|
void subulchk(unsigned long a, unsigned long b)
|
1991-03-05 11:56:39 +00:00
|
|
|
{
|
2018-06-25 20:22:37 +00:00
|
|
|
if (b < a)
|
|
|
|
TRP(M2_UUVFL);
|
1991-03-05 11:56:39 +00:00
|
|
|
}
|
|
|
|
#endif
|