Header And Logo

PostgreSQL
| The world's most advanced open source database.

Data Structures | Defines | Typedefs | Functions | Variables

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

Defines

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

Typedefs

typedef struct Complex Complex

Functions

Datum complex_in (PG_FUNCTION_ARGS)
Datum complex_out (PG_FUNCTION_ARGS)
Datum complex_recv (PG_FUNCTION_ARGS)
Datum complex_send (PG_FUNCTION_ARGS)
Datum complex_add (PG_FUNCTION_ARGS)
Datum complex_abs_lt (PG_FUNCTION_ARGS)
Datum complex_abs_le (PG_FUNCTION_ARGS)
Datum complex_abs_eq (PG_FUNCTION_ARGS)
Datum complex_abs_ge (PG_FUNCTION_ARGS)
Datum complex_abs_gt (PG_FUNCTION_ARGS)
Datum complex_abs_cmp (PG_FUNCTION_ARGS)
 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)
static int complex_abs_cmp_internal (Complex *a, Complex *b)
 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)

Variables

 PG_MODULE_MAGIC

Define Documentation

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

Definition at line 148 of file complex.c.

Referenced by complex_abs_cmp_internal().


Typedef Documentation

typedef struct Complex Complex

Function Documentation

Datum complex_abs_cmp ( PG_FUNCTION_ARGS   ) 
static int complex_abs_cmp_internal ( Complex a,
Complex b 
) [static]

Definition at line 151 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().

{
    double      amag = Mag(a),
                bmag = Mag(b);

    if (amag < bmag)
        return -1;
    if (amag > bmag)
        return 1;
    return 0;
}

Datum complex_abs_eq ( PG_FUNCTION_ARGS   ) 
Datum complex_abs_ge ( PG_FUNCTION_ARGS   ) 
Datum complex_abs_gt ( PG_FUNCTION_ARGS   ) 
Datum complex_abs_le ( PG_FUNCTION_ARGS   ) 
Datum complex_abs_lt ( PG_FUNCTION_ARGS   ) 
Datum complex_add ( PG_FUNCTION_ARGS   ) 

Definition at line 124 of file complex.c.

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

{
    Complex    *a = (Complex *) PG_GETARG_POINTER(0);
    Complex    *b = (Complex *) PG_GETARG_POINTER(1);
    Complex    *result;

    result = (Complex *) palloc(sizeof(Complex));
    result->x = a->x + b->x;
    result->y = a->y + b->y;
    PG_RETURN_POINTER(result);
}

Datum complex_in ( PG_FUNCTION_ARGS   ) 

Definition at line 49 of file complex.c.

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

{
    char       *str = PG_GETARG_CSTRING(0);
    double      x,
                y;
    Complex    *result;

    if (sscanf(str, " ( %lf , %lf )", &x, &y) != 2)
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
                 errmsg("invalid input syntax for complex: \"%s\"",
                        str)));

    result = (Complex *) palloc(sizeof(Complex));
    result->x = x;
    result->y = y;
    PG_RETURN_POINTER(result);
}

Datum complex_out ( PG_FUNCTION_ARGS   ) 

Definition at line 71 of file complex.c.

References palloc(), PG_GETARG_POINTER, PG_RETURN_CSTRING, snprintf(), Complex::x, and Complex::y.

{
    Complex    *complex = (Complex *) PG_GETARG_POINTER(0);
    char       *result;

    result = (char *) palloc(100);
    snprintf(result, 100, "(%g,%g)", complex->x, complex->y);
    PG_RETURN_CSTRING(result);
}

Datum complex_recv ( PG_FUNCTION_ARGS   ) 

Definition at line 90 of file complex.c.

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

{
    StringInfo  buf = (StringInfo) PG_GETARG_POINTER(0);
    Complex    *result;

    result = (Complex *) palloc(sizeof(Complex));
    result->x = pq_getmsgfloat8(buf);
    result->y = pq_getmsgfloat8(buf);
    PG_RETURN_POINTER(result);
}

Datum complex_send ( PG_FUNCTION_ARGS   ) 
PG_FUNCTION_INFO_V1 ( complex_in   ) 
PG_FUNCTION_INFO_V1 ( complex_abs_gt   ) 
PG_FUNCTION_INFO_V1 ( complex_abs_ge   ) 
PG_FUNCTION_INFO_V1 ( complex_abs_eq   ) 
PG_FUNCTION_INFO_V1 ( complex_abs_le   ) 
PG_FUNCTION_INFO_V1 ( complex_abs_lt   ) 
PG_FUNCTION_INFO_V1 ( complex_abs_cmp   ) 
PG_FUNCTION_INFO_V1 ( complex_add   ) 
PG_FUNCTION_INFO_V1 ( complex_send   ) 
PG_FUNCTION_INFO_V1 ( complex_recv   ) 
PG_FUNCTION_INFO_V1 ( complex_out   ) 

Variable Documentation

Definition at line 16 of file complex.c.