* workings can be found in the book "Software Solutions in C" by
* Dale Schumacher, Academic Press, ISBN: 0-12-632360-7.
*
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.7 1997/04/28 16:15:13 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.8 1997/08/21 23:56:37 momjian Exp $
*/
#include <stdio.h>
if (!PointerIsValid(result = PALLOCTYPE(Cash)))
elog(WARN,"Memory allocation failed, can't divide cash",NULL);
+ if (*f == 0.0)
+ elog(WARN,"cash_div: divide by 0.0 error");
+
*result = rint(*c / *f);
return(result);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.32 1997/08/19 21:34:34 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.33 1997/08/21 23:56:40 momjian Exp $
*
*-------------------------------------------------------------------------
*/
TimeSpan *
-datetime_sub(DateTime *datetime1, DateTime *datetime2)
+datetime_mi(DateTime *datetime1, DateTime *datetime2)
{
TimeSpan *result;
result->month = 0;
return(result);
-} /* datetime_sub() */
+} /* datetime_mi() */
-/* datetime_add_span()
+/* datetime_pl_span()
* Add a timespan to a datetime data type.
* Note that timespan has provisions for qualitative year/month
* units, so try to do the right thing with them.
* to the last day of month.
*/
DateTime *
-datetime_add_span(DateTime *datetime, TimeSpan *span)
+datetime_pl_span(DateTime *datetime, TimeSpan *span)
{
DateTime *result;
DateTime dt;
result = PALLOCTYPE(DateTime);
#ifdef DATEDEBUG
-printf( "datetime_add_span- add %f to %d %f\n", *datetime, span->month, span->time);
+printf( "datetime_pl_span- add %f to %d %f\n", *datetime, span->month, span->time);
#endif
if (DATETIME_NOT_FINITE(*datetime)) {
if (datetime2tm( dt, &tz, tm, &fsec, &tzn) == 0) {
#ifdef DATEDEBUG
-printf( "datetime_add_span- date was %04d-%02d-%02d %02d:%02d:%02d\n",
+printf( "datetime_pl_span- date was %04d-%02d-%02d %02d:%02d:%02d\n",
tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
#endif
tm->tm_mon += span->month;
};
#ifdef DATEDEBUG
-printf( "datetime_add_span- date becomes %04d-%02d-%02d %02d:%02d:%02d\n",
+printf( "datetime_pl_span- date becomes %04d-%02d-%02d %02d:%02d:%02d\n",
tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
#endif
if (tm2datetime( tm, fsec, &tz, &dt) != 0)
};
return(result);
-} /* datetime_add_span() */
+} /* datetime_pl_span() */
DateTime *
-datetime_sub_span(DateTime *datetime, TimeSpan *span)
+datetime_mi_span(DateTime *datetime, TimeSpan *span)
{
DateTime *result;
TimeSpan tspan;
tspan.month = -span->month;
tspan.time = -span->time;
- result = datetime_add_span( datetime, &tspan);
+ result = datetime_pl_span( datetime, &tspan);
return(result);
-} /* datetime_sub_span() */
+} /* datetime_mi_span() */
TimeSpan *
TimeSpan *
-timespan_add(TimeSpan *span1, TimeSpan *span2)
+timespan_pl(TimeSpan *span1, TimeSpan *span2)
{
TimeSpan *result;
result->time = JROUND(span1->time + span2->time);
return(result);
-} /* timespan_add() */
+} /* timespan_pl() */
TimeSpan *
-timespan_sub(TimeSpan *span1, TimeSpan *span2)
+timespan_mi(TimeSpan *span1, TimeSpan *span2)
{
TimeSpan *result;
result->time = JROUND(span1->time - span2->time);
return(result);
-} /* timespan_sub() */
+} /* timespan_mi() */
+TimeSpan *
+timespan_div(TimeSpan *span1, float8 *arg2)
+{
+ TimeSpan *result;
+
+ if ((!PointerIsValid(span1)) || (!PointerIsValid(arg2)))
+ return NULL;
+
+ if (!PointerIsValid(result = PALLOCTYPE(TimeSpan)))
+ elog(WARN,"Memory allocation failed, can't subtract timespans",NULL);
+
+ if (*arg2 == 0.0)
+ elog(WARN,"timespan_div: divide by 0.0 error");
+
+ result->month = rint(span1->month / *arg2);
+ result->time = JROUND(span1->time / *arg2);
+
+ return(result);
+} /* timespan_div() */
/* datetime_age()
* Calculate time difference while retaining year/month fields.
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.15 1997/08/19 21:34:39 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.16 1997/08/21 23:56:41 momjian Exp $
*
*-------------------------------------------------------------------------
*/
div = (p2->x*p2->x) + (p2->y*p2->y);
+ if (div == 0.0)
+ elog(WARN,"point_div: divide by 0.0 error");
+
result->x = ((p1->x*p2->x) + (p1->y*p2->y)) / div;
result->y = ((p2->x*p1->y) - (p2->y*p1->x)) / div;
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: pg_aggregate.h,v 1.7 1997/04/27 19:22:36 thomas Exp $
+ * $Id: pg_aggregate.h,v 1.8 1997/08/21 23:56:45 momjian Exp $
*
* NOTES
* the genbki.sh script reads this file and generates .bki
DATA(insert OID = 0 ( avg PGUID float4pl float4inc float4div 700 700 700 700 _null_ 0.0 ));
DATA(insert OID = 0 ( avg PGUID float8pl float8inc float8div 701 701 701 701 _null_ 0.0 ));
DATA(insert OID = 0 ( avg PGUID cash_pl float8inc cash_div 790 790 701 790 _null_ 0.0 ));
+DATA(insert OID = 0 ( avg PGUID timespan_pl float8inc timespan_div 1186 1186 701 1186 _null_ 0.0 ));
DATA(insert OID = 0 ( sum PGUID int4pl - - 23 23 0 23 _null_ _null_ ));
DATA(insert OID = 0 ( sum PGUID int2pl - - 21 21 0 21 _null_ _null_ ));
DATA(insert OID = 0 ( sum PGUID float4pl - - 700 700 0 700 _null_ _null_ ));
DATA(insert OID = 0 ( sum PGUID float8pl - - 701 701 0 701 _null_ _null_ ));
DATA(insert OID = 0 ( sum PGUID cash_pl - - 790 790 0 790 _null_ _null_ ));
+DATA(insert OID = 0 ( sum PGUID timespan_pl - - 1186 1186 0 1186 _null_ _null_ ));
DATA(insert OID = 0 ( max PGUID int4larger - - 23 23 0 23 _null_ _null_ ));
DATA(insert OID = 0 ( max PGUID int2larger - - 21 21 0 21 _null_ _null_ ));
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: pg_operator.h,v 1.12 1997/07/29 16:17:50 thomas Exp $
+ * $Id: pg_operator.h,v 1.13 1997/08/21 23:56:48 momjian Exp $
*
* NOTES
* the genbki.sh script reads this file and generates .bki
DATA(insert OID = 1324 ( ">" PGUID 0 b t f 1184 1184 16 1323 1323 0 0 datetime_gt intltsel intltjoinsel ));
DATA(insert OID = 1325 ( ">=" PGUID 0 b t f 1184 1184 16 1322 1322 0 0 datetime_ge intltsel intltjoinsel ));
-DATA(insert OID = 1327 ( "+" PGUID 0 b t f 1184 1186 1184 1327 0 0 0 datetime_add_span - - ));
-DATA(insert OID = 1328 ( "-" PGUID 0 b t f 1184 1184 1186 0 0 0 0 datetime_sub - - ));
-DATA(insert OID = 1329 ( "-" PGUID 0 b t f 1184 1186 1184 0 0 0 0 datetime_sub_span - - ));
+DATA(insert OID = 1327 ( "+" PGUID 0 b t f 1184 1186 1184 1327 0 0 0 datetime_pl_span - - ));
+DATA(insert OID = 1328 ( "-" PGUID 0 b t f 1184 1184 1186 0 0 0 0 datetime_mi - - ));
+DATA(insert OID = 1329 ( "-" PGUID 0 b t f 1184 1186 1184 0 0 0 0 datetime_mi_span - - ));
/* timespan operators */
DATA(insert OID = 1330 ( "=" PGUID 0 b t f 1186 1186 16 1330 1331 1332 1332 timespan_eq eqsel eqjoinsel ));
DATA(insert OID = 1335 ( ">=" PGUID 0 b t f 1186 1186 16 1332 1332 0 0 timespan_ge intltsel intltjoinsel ));
DATA(insert OID = 1336 ( "-" PGUID 0 l t f 0 1186 1186 0 0 0 0 timespan_um 0 0 ));
-DATA(insert OID = 1337 ( "+" PGUID 0 b t f 1186 1186 1186 1337 0 0 0 timespan_add - - ));
-DATA(insert OID = 1338 ( "-" PGUID 0 b t f 1186 1186 1186 0 0 0 0 timespan_sub - - ));
+DATA(insert OID = 1337 ( "+" PGUID 0 b t f 1186 1186 1186 1337 0 0 0 timespan_pl - - ));
+DATA(insert OID = 1338 ( "-" PGUID 0 b t f 1186 1186 1186 0 0 0 0 timespan_mi - - ));
/* float48 operators */
DATA(insert OID = 1116 ( "+" PGUID 0 b t f 700 701 701 1116 0 0 0 float48pl - - ));
DATA(insert OID = 1566 ( "##" PGUID 0 b t f 601 628 600 0 0 0 0 close_sl - - ));
DATA(insert OID = 1567 ( "##" PGUID 0 b t f 601 603 600 0 0 0 0 close_sb - - ));
DATA(insert OID = 1568 ( "##" PGUID 0 b t f 628 603 600 0 0 0 0 close_lb - - ));
+DATA(insert OID = 1585 ( "/" PGUID 0 b t f 1186 1186 1186 0 0 0 0 timespan_div - - ));
/*
* function prototypes
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: pg_proc.h,v 1.24 1997/07/29 16:17:52 thomas Exp $
+ * $Id: pg_proc.h,v 1.25 1997/08/21 23:56:51 momjian Exp $
*
* NOTES
* The script catalog/genbki.sh reads this file and generates .bki
DATA(insert OID = 1166 ( timespan_ge PGUID 11 f t f 2 f 16 "1186 1186" 100 0 0 100 foo bar ));
DATA(insert OID = 1167 ( timespan_gt PGUID 11 f t f 2 f 16 "1186 1186" 100 0 0 100 foo bar ));
DATA(insert OID = 1168 ( timespan_um PGUID 11 f t f 1 f 1186 "1186" 100 0 0 100 foo bar ));
-DATA(insert OID = 1169 ( timespan_add PGUID 11 f t f 2 f 1186 "1186 1186" 100 0 0 100 foo bar ));
-DATA(insert OID = 1170 ( timespan_sub PGUID 11 f t f 2 f 1186 "1186 1186" 100 0 0 100 foo bar ));
+DATA(insert OID = 1169 ( timespan_pl PGUID 11 f t f 2 f 1186 "1186 1186" 100 0 0 100 foo bar ));
+DATA(insert OID = 1170 ( timespan_mi PGUID 11 f t f 2 f 1186 "1186 1186" 100 0 0 100 foo bar ));
DATA(insert OID = 1171 ( datetime_part PGUID 11 f t f 2 f 701 "25 1184" 100 0 0 100 foo bar ));
DATA(insert OID = 1172 ( timespan_part PGUID 11 f t f 2 f 701 "25 1186" 100 0 0 100 foo bar ));
DATA(insert OID = 1179 ( abstime_date PGUID 11 f t f 1 f 1082 "702" 100 0 0 100 foo bar ));
DATA(insert OID = 1180 ( datetime_abstime PGUID 11 f t f 1 f 702 "1184" 100 0 0 100 foo bar ));
-DATA(insert OID = 1188 ( datetime_sub PGUID 11 f t f 2 f 1186 "1184 1184" 100 0 0 100 foo bar ));
-DATA(insert OID = 1189 ( datetime_add_span PGUID 11 f t f 2 f 1184 "1184 1186" 100 0 0 100 foo bar ));
-DATA(insert OID = 1190 ( datetime_sub_span PGUID 11 f t f 2 f 1184 "1184 1186" 100 0 0 100 foo bar ));
+DATA(insert OID = 1188 ( datetime_mi PGUID 11 f t f 2 f 1186 "1184 1184" 100 0 0 100 foo bar ));
+DATA(insert OID = 1189 ( datetime_pl_span PGUID 11 f t f 2 f 1184 "1184 1186" 100 0 0 100 foo bar ));
+DATA(insert OID = 1190 ( datetime_mi_span PGUID 11 f t f 2 f 1184 "1184 1186" 100 0 0 100 foo bar ));
DATA(insert OID = 1191 ( text_datetime PGUID 11 f t f 1 f 1184 "25" 100 0 0 100 foo bar ));
DATA(insert OID = 1192 ( datetime_text PGUID 11 f t f 1 f 25 "1184" 100 0 0 100 foo bar ));
DATA(insert OID = 1193 ( timespan_text PGUID 11 f t f 1 f 1186 "25" 100 0 0 100 foo bar ));
DATA(insert OID = 883 ( substr PGUID 14 f t f 2 f 25 "25 23" 100 0 0 100 "select substr($1, $2, 10000)" - ));
DATA(insert OID = 884 ( btrim PGUID 11 f t f 2 f 25 "25 25" 100 0 0 100 foo bar ));
DATA(insert OID = 885 ( btrim PGUID 14 f t f 1 f 25 "25" 100 0 0 100 "select btrim($1, \' \')" - ));
+/* XXX Help, where should I go to */
+DATA(insert OID = 1586 ( timespan_div PGUID 11 f t f 2 f 1186 "1186 701" 100 0 0 100 foo bar ));
/* SEQUENCEs nextval & currval functions */
DATA(insert OID = 1317 ( nextval PGUID 11 f t f 1 f 23 "25" 100 0 0 100 foo bar ));
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: dt.h,v 1.16 1997/08/19 21:40:30 momjian Exp $
+ * $Id: dt.h,v 1.17 1997/08/21 23:57:00 momjian Exp $
*
*-------------------------------------------------------------------------
*/
extern text *datetime_zone(text *zone, DateTime *datetime);
extern TimeSpan *timespan_um(TimeSpan *span);
-extern TimeSpan *timespan_add(TimeSpan *span1, TimeSpan *span2);
-extern TimeSpan *timespan_sub(TimeSpan *span1, TimeSpan *span2);
+extern TimeSpan *timespan_pl(TimeSpan *span1, TimeSpan *span2);
+extern TimeSpan *timespan_mi(TimeSpan *span1, TimeSpan *span2);
+extern TimeSpan *timespan_div(TimeSpan *span1, float8 *arg2);
-extern TimeSpan *datetime_sub(DateTime *dt1, DateTime *dt2);
-extern DateTime *datetime_add_span(DateTime *dt, TimeSpan *span);
-extern DateTime *datetime_sub_span(DateTime *dt, TimeSpan *span);
+extern TimeSpan *datetime_mi(DateTime *dt1, DateTime *dt2);
+extern DateTime *datetime_pl_span(DateTime *dt, TimeSpan *span);
+extern DateTime *datetime_mi_span(DateTime *dt, TimeSpan *span);
extern TimeSpan *datetime_age(DateTime *dt1, DateTime *dt2);
extern void GetCurrentTime(struct tm *tm);