PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
complex.c File Reference
#include "postgres.h"
#include "fmgr.h"
#include "libpq/pqformat.h"
Include dependency graph for complex.c:

Go to the source code of this file.

Data Structures

struct  Complex
 

Macros

#define Mag(c)   ((c)->x*(c)->x + (c)->y*(c)->y)
 

Typedefs

typedef struct Complex Complex
 

Functions

 PG_FUNCTION_INFO_V1 (complex_in)
 
Datum complex_in (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (complex_out)
 
Datum complex_out (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (complex_recv)
 
Datum complex_recv (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (complex_send)
 
Datum complex_send (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (complex_add)
 
Datum complex_add (PG_FUNCTION_ARGS)
 
static int complex_abs_cmp_internal (Complex *a, Complex *b)
 
 PG_FUNCTION_INFO_V1 (complex_abs_lt)
 
Datum complex_abs_lt (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (complex_abs_le)
 
Datum complex_abs_le (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (complex_abs_eq)
 
Datum complex_abs_eq (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (complex_abs_ge)
 
Datum complex_abs_ge (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (complex_abs_gt)
 
Datum complex_abs_gt (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (complex_abs_cmp)
 
Datum complex_abs_cmp (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 

Macro Definition Documentation

#define Mag (   c)    ((c)->x*(c)->x + (c)->y*(c)->y)

Definition at line 129 of file complex.c.

Referenced by complex_abs_cmp_internal().

Typedef Documentation

Function Documentation

Datum complex_abs_cmp ( PG_FUNCTION_ARGS  )

Definition at line 203 of file complex.c.

References complex_abs_cmp_internal(), PG_GETARG_POINTER, and PG_RETURN_INT32.

204 {
205  Complex *a = (Complex *) PG_GETARG_POINTER(0);
206  Complex *b = (Complex *) PG_GETARG_POINTER(1);
207 
209 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static int complex_abs_cmp_internal(Complex *a, Complex *b)
Definition: complex.c:132
static int complex_abs_cmp_internal ( Complex a,
Complex b 
)
static

Definition at line 132 of file complex.c.

References Mag.

Referenced by complex_abs_cmp(), complex_abs_eq(), complex_abs_ge(), complex_abs_gt(), complex_abs_le(), and complex_abs_lt().

133 {
134  double amag = Mag(a),
135  bmag = Mag(b);
136 
137  if (amag < bmag)
138  return -1;
139  if (amag > bmag)
140  return 1;
141  return 0;
142 }
#define Mag(c)
Definition: complex.c:129
Datum complex_abs_eq ( PG_FUNCTION_ARGS  )

Definition at line 170 of file complex.c.

References complex_abs_cmp_internal(), PG_GETARG_POINTER, and PG_RETURN_BOOL.

171 {
172  Complex *a = (Complex *) PG_GETARG_POINTER(0);
173  Complex *b = (Complex *) PG_GETARG_POINTER(1);
174 
176 }
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static int complex_abs_cmp_internal(Complex *a, Complex *b)
Definition: complex.c:132
Datum complex_abs_ge ( PG_FUNCTION_ARGS  )

Definition at line 181 of file complex.c.

References complex_abs_cmp_internal(), PG_GETARG_POINTER, and PG_RETURN_BOOL.

182 {
183  Complex *a = (Complex *) PG_GETARG_POINTER(0);
184  Complex *b = (Complex *) PG_GETARG_POINTER(1);
185 
187 }
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static int complex_abs_cmp_internal(Complex *a, Complex *b)
Definition: complex.c:132
Datum complex_abs_gt ( PG_FUNCTION_ARGS  )

Definition at line 192 of file complex.c.

References complex_abs_cmp_internal(), PG_GETARG_POINTER, and PG_RETURN_BOOL.

193 {
194  Complex *a = (Complex *) PG_GETARG_POINTER(0);
195  Complex *b = (Complex *) PG_GETARG_POINTER(1);
196 
198 }
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static int complex_abs_cmp_internal(Complex *a, Complex *b)
Definition: complex.c:132
Datum complex_abs_le ( PG_FUNCTION_ARGS  )

Definition at line 159 of file complex.c.

References complex_abs_cmp_internal(), PG_GETARG_POINTER, and PG_RETURN_BOOL.

160 {
161  Complex *a = (Complex *) PG_GETARG_POINTER(0);
162  Complex *b = (Complex *) PG_GETARG_POINTER(1);
163 
165 }
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static int complex_abs_cmp_internal(Complex *a, Complex *b)
Definition: complex.c:132
Datum complex_abs_lt ( PG_FUNCTION_ARGS  )

Definition at line 148 of file complex.c.

References complex_abs_cmp_internal(), PG_GETARG_POINTER, and PG_RETURN_BOOL.

149 {
150  Complex *a = (Complex *) PG_GETARG_POINTER(0);
151  Complex *b = (Complex *) PG_GETARG_POINTER(1);
152 
154 }
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static int complex_abs_cmp_internal(Complex *a, Complex *b)
Definition: complex.c:132
Datum complex_add ( PG_FUNCTION_ARGS  )

Definition at line 105 of file complex.c.

References palloc(), PG_GETARG_POINTER, PG_RETURN_POINTER, result, Complex::x, and Complex::y.

106 {
107  Complex *a = (Complex *) PG_GETARG_POINTER(0);
108  Complex *b = (Complex *) PG_GETARG_POINTER(1);
109  Complex *result;
110 
111  result = (Complex *) palloc(sizeof(Complex));
112  result->x = a->x + b->x;
113  result->y = a->y + b->y;
114  PG_RETURN_POINTER(result);
115 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
return result
Definition: formatting.c:1618
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
double y
Definition: complex.c:20
void * palloc(Size size)
Definition: mcxt.c:849
double x
Definition: complex.c:19
Datum complex_in ( PG_FUNCTION_ARGS  )

Definition at line 31 of file complex.c.

References ereport, errcode(), errmsg(), ERROR, palloc(), PG_GETARG_CSTRING, PG_RETURN_POINTER, result, Complex::x, and Complex::y.

32 {
33  char *str = PG_GETARG_CSTRING(0);
34  double x,
35  y;
36  Complex *result;
37 
38  if (sscanf(str, " ( %lf , %lf )", &x, &y) != 2)
39  ereport(ERROR,
40  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
41  errmsg("invalid input syntax for complex: \"%s\"",
42  str)));
43 
44  result = (Complex *) palloc(sizeof(Complex));
45  result->x = x;
46  result->y = y;
47  PG_RETURN_POINTER(result);
48 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
double y
Definition: complex.c:20
void * palloc(Size size)
Definition: mcxt.c:849
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
double x
Definition: complex.c:19
Datum complex_out ( PG_FUNCTION_ARGS  )

Definition at line 53 of file complex.c.

References PG_GETARG_POINTER, PG_RETURN_CSTRING, psprintf(), result, Complex::x, and Complex::y.

54 {
55  Complex *complex = (Complex *) PG_GETARG_POINTER(0);
56  char *result;
57 
58  result = psprintf("(%g,%g)", complex->x, complex->y);
59  PG_RETURN_CSTRING(result);
60 }
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
return result
Definition: formatting.c:1618
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
double y
Definition: complex.c:20
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
double x
Definition: complex.c:19
Datum complex_recv ( PG_FUNCTION_ARGS  )

Definition at line 71 of file complex.c.

References buf, palloc(), PG_GETARG_POINTER, PG_RETURN_POINTER, pq_getmsgfloat8(), result, Complex::x, and Complex::y.

72 {
74  Complex *result;
75 
76  result = (Complex *) palloc(sizeof(Complex));
77  result->x = pq_getmsgfloat8(buf);
78  result->y = pq_getmsgfloat8(buf);
79  PG_RETURN_POINTER(result);
80 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
StringInfoData * StringInfo
Definition: stringinfo.h:46
return result
Definition: formatting.c:1618
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static char * buf
Definition: pg_test_fsync.c:65
double y
Definition: complex.c:20
float8 pq_getmsgfloat8(StringInfo msg)
Definition: pqformat.c:530
void * palloc(Size size)
Definition: mcxt.c:849
double x
Definition: complex.c:19
Datum complex_send ( PG_FUNCTION_ARGS  )

Definition at line 85 of file complex.c.

References buf, PG_GETARG_POINTER, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), pq_sendfloat8(), Complex::x, and Complex::y.

86 {
87  Complex *complex = (Complex *) PG_GETARG_POINTER(0);
89 
90  pq_begintypsend(&buf);
91  pq_sendfloat8(&buf, complex->x);
92  pq_sendfloat8(&buf, complex->y);
94 }
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:359
void pq_sendfloat8(StringInfo buf, float8 f)
Definition: pqformat.c:324
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:329
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:379
static char * buf
Definition: pg_test_fsync.c:65
double y
Definition: complex.c:20
double x
Definition: complex.c:19
PG_FUNCTION_INFO_V1 ( complex_in  )
PG_FUNCTION_INFO_V1 ( complex_out  )
PG_FUNCTION_INFO_V1 ( complex_recv  )
PG_FUNCTION_INFO_V1 ( complex_send  )
PG_FUNCTION_INFO_V1 ( complex_add  )
PG_FUNCTION_INFO_V1 ( complex_abs_lt  )
PG_FUNCTION_INFO_V1 ( complex_abs_le  )
PG_FUNCTION_INFO_V1 ( complex_abs_eq  )
PG_FUNCTION_INFO_V1 ( complex_abs_ge  )
PG_FUNCTION_INFO_V1 ( complex_abs_gt  )
PG_FUNCTION_INFO_V1 ( complex_abs_cmp  )

Variable Documentation

PG_MODULE_MAGIC

Definition at line 15 of file complex.c.