9
9
* workings can be found in the book "Software Solutions in C" by
10
10
* Dale Schumacher, Academic Press, ISBN: 0-12-632360-7.
11
11
*
12
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.43 2000/07/07 18:49:52 momjian Exp $
12
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.44 2000/08/01 18:29:35 tgl Exp $
13
13
*/
14
14
15
15
#include <limits.h>
@@ -425,31 +425,31 @@ cash_mi(Cash *c1, Cash *c2)
425
425
/* cash_mul_flt8()
426
426
* Multiply cash by float8.
427
427
*/
428
- Cash *
429
- cash_mul_flt8 (Cash * c , float8 * f )
428
+ Datum
429
+ cash_mul_flt8 (PG_FUNCTION_ARGS )
430
430
{
431
- Cash * result ;
432
-
433
- if (!PointerIsValid (f ) || !PointerIsValid (c ))
434
- return NULL ;
435
-
436
- if (!PointerIsValid (result = palloc (sizeof (Cash ))))
437
- elog (ERROR , "Memory allocation failed, can't multiply cash" );
438
-
439
- * result = ((* f ) * (* c ));
431
+ Cash c = PG_GETARG_CASH (0 );
432
+ float8 f = PG_GETARG_FLOAT8 (1 );
433
+ Cash result ;
440
434
441
- return result ;
442
- } /* cash_mul_flt8() */
435
+ result = c * f ;
436
+ PG_RETURN_CASH (result );
437
+ }
443
438
444
439
445
440
/* flt8_mul_cash()
446
441
* Multiply float8 by cash.
447
442
*/
448
- Cash *
449
- flt8_mul_cash (float8 * f , Cash * c )
443
+ Datum
444
+ flt8_mul_cash (PG_FUNCTION_ARGS )
450
445
{
451
- return cash_mul_flt8 (c , f );
452
- } /* flt8_mul_cash() */
446
+ float8 f = PG_GETARG_FLOAT8 (0 );
447
+ Cash c = PG_GETARG_CASH (1 );
448
+ Cash result ;
449
+
450
+ result = f * c ;
451
+ PG_RETURN_CASH (result );
452
+ }
453
453
454
454
455
455
/* cash_div_flt8()
@@ -458,53 +458,48 @@ flt8_mul_cash(float8 *f, Cash *c)
458
458
* XXX Don't know if rounding or truncating is correct behavior.
459
459
* Round for now. - tgl 97/04/15
460
460
*/
461
- Cash *
462
- cash_div_flt8 (Cash * c , float8 * f )
461
+ Datum
462
+ cash_div_flt8 (PG_FUNCTION_ARGS )
463
463
{
464
- Cash * result ;
465
-
466
- if (!PointerIsValid (f ) || !PointerIsValid (c ))
467
- return NULL ;
468
-
469
- if (!PointerIsValid (result = palloc (sizeof (Cash ))))
470
- elog (ERROR , "Memory allocation failed, can't divide cash" );
464
+ Cash c = PG_GETARG_CASH (0 );
465
+ float8 f = PG_GETARG_FLOAT8 (1 );
466
+ Cash result ;
471
467
472
- if (* f == 0.0 )
468
+ if (f == 0.0 )
473
469
elog (ERROR , "cash_div: divide by 0.0 error" );
474
470
475
- * result = rint (* c / * f );
476
-
477
- return result ;
478
- } /* cash_div_flt8() */
471
+ result = rint (c / f );
472
+ PG_RETURN_CASH (result );
473
+ }
479
474
480
475
/* cash_mul_flt4()
481
476
* Multiply cash by float4.
482
477
*/
483
- Cash *
484
- cash_mul_flt4 (Cash * c , float4 * f )
478
+ Datum
479
+ cash_mul_flt4 (PG_FUNCTION_ARGS )
485
480
{
486
- Cash * result ;
487
-
488
- if (!PointerIsValid (f ) || !PointerIsValid (c ))
489
- return NULL ;
490
-
491
- if (!PointerIsValid (result = palloc (sizeof (Cash ))))
492
- elog (ERROR , "Memory allocation failed, can't multiply cash" );
493
-
494
- * result = ((* f ) * (* c ));
481
+ Cash c = PG_GETARG_CASH (0 );
482
+ float4 f = PG_GETARG_FLOAT4 (1 );
483
+ Cash result ;
495
484
496
- return result ;
497
- } /* cash_mul_flt4() */
485
+ result = c * f ;
486
+ PG_RETURN_CASH (result );
487
+ }
498
488
499
489
500
490
/* flt4_mul_cash()
501
- * Multiply float4 by float4 .
491
+ * Multiply float4 by cash .
502
492
*/
503
- Cash *
504
- flt4_mul_cash (float4 * f , Cash * c )
493
+ Datum
494
+ flt4_mul_cash (PG_FUNCTION_ARGS )
505
495
{
506
- return cash_mul_flt4 (c , f );
507
- } /* flt4_mul_cash() */
496
+ float4 f = PG_GETARG_FLOAT4 (0 );
497
+ Cash c = PG_GETARG_CASH (1 );
498
+ Cash result ;
499
+
500
+ result = f * c ;
501
+ PG_RETURN_CASH (result );
502
+ }
508
503
509
504
510
505
/* cash_div_flt4()
@@ -513,24 +508,19 @@ flt4_mul_cash(float4 *f, Cash *c)
513
508
* XXX Don't know if rounding or truncating is correct behavior.
514
509
* Round for now. - tgl 97/04/15
515
510
*/
516
- Cash *
517
- cash_div_flt4 (Cash * c , float4 * f )
511
+ Datum
512
+ cash_div_flt4 (PG_FUNCTION_ARGS )
518
513
{
519
- Cash * result ;
520
-
521
- if (!PointerIsValid (f ) || !PointerIsValid (c ))
522
- return NULL ;
523
-
524
- if (!PointerIsValid (result = palloc (sizeof (Cash ))))
525
- elog (ERROR , "Memory allocation failed, can't divide cash" );
514
+ Cash c = PG_GETARG_CASH (0 );
515
+ float4 f = PG_GETARG_FLOAT4 (1 );
516
+ Cash result ;
526
517
527
- if (* f == 0.0 )
518
+ if (f == 0.0 )
528
519
elog (ERROR , "cash_div: divide by 0.0 error" );
529
520
530
- * result = rint (* c / * f );
531
-
532
- return result ;
533
- } /* cash_div_flt4() */
521
+ result = rint (c / f );
522
+ PG_RETURN_CASH (result );
523
+ }
534
524
535
525
536
526
/* cash_mul_int4()
0 commit comments