turns out the imult routines (which I never used) were incorrect.
Noted by Matthew Dempsky open_* from open.h now open in large file mode
This commit is contained in:
parent
46dcfbdce1
commit
19202d2320
3
CHANGES
3
CHANGES
@ -4,6 +4,9 @@
|
||||
if _XOPEN_SOURCE is defined, which is needed for Solaris.
|
||||
OpenBSD sucks. I checked in a _really_ kludge now. Please do not
|
||||
use OpenBSD if you have a choice. Or Solaris, for that matter.
|
||||
turns out the imult routines (which I never used) were incorrect.
|
||||
Noted by Matthew Dempsky
|
||||
open_* from open.h now open in large file mode
|
||||
|
||||
0.23:
|
||||
also recognize EPFNOSUPPORT as EAFNOSUPPORT (groan)
|
||||
|
@ -1,11 +1,8 @@
|
||||
#include "safemult.h"
|
||||
|
||||
int imult16(int16 a,int16 b,int16* c) {
|
||||
int neg=(a<0);
|
||||
uint16 d;
|
||||
if (neg) a=-a;
|
||||
if (b<0) { neg^=1; b=-b; }
|
||||
if (umult16(a,b,&d)) return 0;
|
||||
*c=(neg?-d:d);
|
||||
int32 x=(int32)a*b;
|
||||
if ((int16)x != x) return 0;
|
||||
*c=x;
|
||||
return 1;
|
||||
}
|
||||
|
@ -1,11 +1,8 @@
|
||||
#include "safemult.h"
|
||||
|
||||
int imult32(int32 a,int32 b,int32* c) {
|
||||
int neg=(a<0);
|
||||
uint32 d;
|
||||
if (neg) a=-a;
|
||||
if (b<0) { neg^=1; b=-b; }
|
||||
if (umult32(a,b,&d)) return 0;
|
||||
*c=(neg?-d:d);
|
||||
int64 x=(int64)a*b;
|
||||
if ((int32)x != x) return 0;
|
||||
*c=x;
|
||||
return 1;
|
||||
}
|
||||
|
@ -5,7 +5,8 @@ int imult64(int64 a,int64 b,int64* c) {
|
||||
uint64 d;
|
||||
if (neg) a=-a;
|
||||
if (b<0) { neg^=1; b=-b; }
|
||||
if (umult64(a,b,&d)) return 0;
|
||||
if (!umult64(a,b,&d)) return 0;
|
||||
if (d > 0x7fffffffffffffffULL + neg) return 0;
|
||||
*c=(neg?-d:d);
|
||||
return 1;
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "open.h"
|
||||
|
@ -1,3 +1,4 @@
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "open.h"
|
||||
|
@ -1,3 +1,4 @@
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "open.h"
|
||||
|
@ -1,3 +1,4 @@
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "open.h"
|
||||
|
@ -1,3 +1,4 @@
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "open.h"
|
||||
|
@ -1,3 +1,4 @@
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "open.h"
|
||||
|
18
t.c
18
t.c
@ -21,6 +21,7 @@
|
||||
#include <assert.h>
|
||||
#include "errmsg.h"
|
||||
#include "iob.h"
|
||||
#include "safemult.h"
|
||||
|
||||
#define rdtscl(low) \
|
||||
__asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx")
|
||||
@ -328,8 +329,25 @@ int main(int argc,char* argv[]) {
|
||||
write(1,tmp,x);
|
||||
}
|
||||
#endif
|
||||
#if 0
|
||||
printf("%d %d\n",strcmp("foo","bar"),str_diff("foo","bar"));
|
||||
printf("%d %d\n",strcmp("foo","üar"),str_diff("foo","üar"));
|
||||
return 0;
|
||||
#endif
|
||||
{
|
||||
int16 a;
|
||||
int32 b;
|
||||
int64 c;
|
||||
assert(imult16(4,10000,&a)==0);
|
||||
assert(imult16(-4,10000,&a)==0);
|
||||
assert(imult16(5,10,&a)==1 && a==50);
|
||||
assert(imult16(-3,10000,&a)==1 && a==-30000);
|
||||
|
||||
assert(imult32(0x40000000,2,&b)==0);
|
||||
assert(imult32(0x3fffffff,2,&b)==1 && b==0x7ffffffe);
|
||||
|
||||
assert(imult64(0x4000000000000000ll,2,&c)==0);
|
||||
assert(imult64(0x3fffffffffffffffll,2,&c)==1 && c==0x7ffffffffffffffell);
|
||||
}
|
||||
}
|
||||
|
||||
|
26
test/mult.c
Normal file
26
test/mult.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include <assert.h>
|
||||
#include "safemult.h"
|
||||
|
||||
int main() {
|
||||
int16 a;
|
||||
int32 b;
|
||||
int64 c;
|
||||
uint16 d;
|
||||
uint32 e;
|
||||
uint64 f;
|
||||
|
||||
assert(imult16(4,10000,&a)==0);
|
||||
assert(imult16(-4,10000,&a)==0);
|
||||
assert(imult16(5,10,&a)==1 && a==50);
|
||||
assert(imult16(-3,10000,&a)==1 && a==-30000);
|
||||
|
||||
assert(imult32(0x40000000,2,&b)==0);
|
||||
assert(imult32(-0x40000000,2,&b)==1 && b==-0x80000000);
|
||||
assert(imult32(0x3fffffff,2,&b)==1 && b==0x7ffffffe);
|
||||
|
||||
assert(imult64(0x4000000000000000ll,2,&c)==0);
|
||||
assert(imult64(-0x4000000000000000ll,2,&c)==1 && c==-0x8000000000000000ll);
|
||||
assert(imult64(0x3fffffffffffffffll,2,&c)==1 && c==0x7ffffffffffffffell);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user