Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
541 B

#if defined(__GNUC__) && (__GNUC__ >= 5)
#include "uint16.h"
int imult16( int16 a, int16 b, int16* c) { return !__builtin_mul_overflow(a,b,c); }
#include "safemult.h"
int imult16(int16 a,int16 b,int16* c) {
int32 x=(int32)a*b;
if ((int16)x != x) return 0;
return 1;
#include <assert.h>
int main() {
int16 a;
assert(imult16(5,10,&a)==1 && a==50);
assert(imult16(-3,10000,&a)==1 && a==-30000);
return 0;