File: longint.h

package info (click to toggle)
rscheme 0.7.2-1.1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 10,672 kB
  • ctags: 12,430
  • sloc: lisp: 37,104; ansic: 29,763; cpp: 2,630; sh: 1,677; makefile: 568; yacc: 202; lex: 175; perl: 33
file content (88 lines) | stat: -rw-r--r-- 2,771 bytes parent folder | download | duplicates (4)
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
80
81
82
83
84
85
86
87
88
/*-----------------------------------------------------------------*-C-*---
 * File:    handc/runtime/longint.h
 *
 *          Copyright (C)1997 Donovan Kolbly <d.kolbly@rscheme.org>
 *          as part of the RScheme project, licensed for free use.
 *          See <http://www.rscheme.org/> for the latest information.
 *
 * File version:     1.5
 * File mod date:    1997.11.29 23:10:50
 * System build:     v0.7.2, 97.12.21
 *
 * Purpose:          Arithmetic and types for 64-bit numbers
 *------------------------------------------------------------------------*/

#ifndef _H_RS_LONGINT
#define _H_RS_LONGINT

#ifndef HAVE_INT_64
typedef struct _int64 {
   UINT_16 digits[4];
} INT_64;

rs_bool LONG_INT_P( obj thing );

INT_64 int_64_add( INT_64 a, INT_64 b );
INT_64 int_64_sub( INT_64 a, INT_64 b );
INT_64 int_64_mul( INT_64 a, INT_64 b );
INT_64 int_64_quotient( INT_64 a, INT_64 b );
INT_64 int_64_modulo( INT_64 a, INT_64 b );
INT_64 int_64_remainder( INT_64 a, INT_64 b );

INT_64 int_64_neg( INT_64 a );
rs_bool int_64_neg_q( INT_64 a );
rs_bool int_64_zero_q( INT_64 a );
rs_bool int_64_eq( INT_64 a, INT_64 b );

int int_64_cmp( INT_64 a, INT_64 b );
rs_bool int_64_gt( INT_64 a, INT_64 b );
rs_bool int_64_ge( INT_64 a, INT_64 b );
#define int_64_lt(a,b) int_64_gt(b,a)
#define int_64_le(a,b) int_64_ge(b,a)

IEEE_64 int_64_to_float( INT_64 a );
INT_32 int_64_to_int_32( INT_64 a );
INT_64 int_32_to_int_64( INT_32 a );
INT_64 float_to_int_64( IEEE_64 a );   /* trunc */

#else
#define int_64_add(a,b) ((a)+(b))
#define int_64_sub(a,b) ((a)-(b))
#define int_64_mul(a,b) ((a)*(b))
#define int_64_quotient(a,b) ((a)/(b))
#define int_64_modulo(a,b) MOD(a,b)
#define int_64_remainder(a,b) REMDR(a,b)

#define int_64_neg(a) (-(a))
#define int_64_neg_q(a) (((a)<0)?YES:NO)
#define int_64_zero_q(a) (((a)==0)?YES:NO)
#define int_64_eq(a,b) (rb_to_bo((a)==(b)))
#define int_64_gt(a,b) (rb_to_bo((a)>(b)))
#define int_64_ge(a,b) (rb_to_bo((a)>=(b)))
#define int_64_lt(a,b) (rb_to_bo((a)<(b)))
#define int_64_le(a,b) (rb_to_bo((a)<=(b)))

#define int_64_to_int_32(x)   ((INT_32)(x))
#define int_32_to_int_64(x)   ((INT_64)(x))
#define int_64_to_float(a)    ((IEEE_64)(a))
#define float_to_int_64(x)    ((INT_64)(x))
#endif

#define fx2int64(x)  int_32_to_int_64(fx2int(x))

obj int_64_compact( INT_64 a );

rs_bool int_64_fit_in_30_q( INT_64 a );
rs_bool int_64_fit_in_32_q( INT_64 a );

obj make_long_int( INT_64 a );

#define extract_int_64(longint) (*((INT_64 *)PTR_TO_DATAPTR(longint)))

/* fills up buffer right-to-left!  buffer starts out pointing
   to the END of the buffer! */

char *int_64_to_string( char *buffer, INT_64 value, unsigned radix );
rs_bool string_to_int_64( char *str, unsigned len, unsigned radix, INT_64 *v );

#endif /* _H_RS_LONGINT */