Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5984746

Browse files
author
Thomas G. Lockhart
committed
Include functions for integer/money arithmetic.
1 parenteba607d commit5984746

File tree

1 file changed

+186
-9
lines changed

1 file changed

+186
-9
lines changed

‎src/backend/utils/adt/cash.c

Lines changed: 186 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* workings can be found in the book "Software Solutions in C" by
1010
* Dale Schumacher, Academic Press, ISBN: 0-12-632360-7.
1111
*
12-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.15 1997/09/18 20:22:12 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.16 1997/09/20 16:15:34 thomas Exp $
1313
*/
1414

1515
#include<stdio.h>
@@ -366,11 +366,11 @@ cash_mi(Cash *c1, Cash *c2)
366366
}/* cash_mi() */
367367

368368

369-
/*cash_mul()
370-
* Multiply cash byfloating point number.
369+
/*cash_mul_flt8()
370+
* Multiply cash byfloat8.
371371
*/
372372
Cash*
373-
cash_mul(Cash*c,float8*f)
373+
cash_mul_flt8(Cash*c,float8*f)
374374
{
375375
Cash*result;
376376

@@ -383,17 +383,27 @@ cash_mul(Cash *c, float8 *f)
383383
*result= ((*f)* (*c));
384384

385385
return (result);
386-
}/*cash_mul() */
386+
}/*cash_mul_flt8() */
387387

388388

389-
/* cash_div()
390-
* Divide cash by floating point number.
389+
/* flt8_mul_cash()
390+
* Multiply float8 by cash.
391+
*/
392+
Cash*
393+
flt8_mul_cash(float8*f,Cash*c)
394+
{
395+
return (cash_mul_flt8(c,f));
396+
}/* flt8_mul_cash() */
397+
398+
399+
/* cash_div_flt8()
400+
* Divide cash by float8.
391401
*
392402
* XXX Don't know if rounding or truncating is correct behavior.
393403
* Round for now. - tgl 97/04/15
394404
*/
395405
Cash*
396-
cash_div(Cash*c,float8*f)
406+
cash_div_flt8(Cash*c,float8*f)
397407
{
398408
Cash*result;
399409

@@ -409,7 +419,174 @@ cash_div(Cash *c, float8 *f)
409419
*result=rint(*c /*f);
410420

411421
return (result);
412-
}/* cash_div() */
422+
}/* cash_div_flt8() */
423+
424+
/* cash_mul_flt4()
425+
* Multiply cash by float4.
426+
*/
427+
Cash*
428+
cash_mul_flt4(Cash*c,float4*f)
429+
{
430+
Cash*result;
431+
432+
if (!PointerIsValid(f)|| !PointerIsValid(c))
433+
return (NULL);
434+
435+
if (!PointerIsValid(result=PALLOCTYPE(Cash)))
436+
elog(WARN,"Memory allocation failed, can't multiply cash",NULL);
437+
438+
*result= ((*f)* (*c));
439+
440+
return (result);
441+
}/* cash_mul_flt4() */
442+
443+
444+
/* flt4_mul_cash()
445+
* Multiply float4 by float4.
446+
*/
447+
Cash*
448+
flt4_mul_cash(float4*f,Cash*c)
449+
{
450+
return (cash_mul_flt4(c,f));
451+
}/* flt4_mul_cash() */
452+
453+
454+
/* cash_div_flt4()
455+
* Divide cash by float4.
456+
*
457+
* XXX Don't know if rounding or truncating is correct behavior.
458+
* Round for now. - tgl 97/04/15
459+
*/
460+
Cash*
461+
cash_div_flt4(Cash*c,float4*f)
462+
{
463+
Cash*result;
464+
465+
if (!PointerIsValid(f)|| !PointerIsValid(c))
466+
return (NULL);
467+
468+
if (!PointerIsValid(result=PALLOCTYPE(Cash)))
469+
elog(WARN,"Memory allocation failed, can't divide cash",NULL);
470+
471+
if (*f==0.0)
472+
elog(WARN,"cash_div: divide by 0.0 error");
473+
474+
*result=rint(*c /*f);
475+
476+
return (result);
477+
}/* cash_div_flt4() */
478+
479+
480+
/* cash_mul_int4()
481+
* Multiply cash by int4.
482+
*/
483+
Cash*
484+
cash_mul_int4(Cash*c,int4i)
485+
{
486+
Cash*result;
487+
488+
if (!PointerIsValid(c))
489+
return (NULL);
490+
491+
if (!PointerIsValid(result=PALLOCTYPE(Cash)))
492+
elog(WARN,"Memory allocation failed, can't multiply cash",NULL);
493+
494+
*result= ((i)* (*c));
495+
496+
return (result);
497+
}/* cash_mul_int4() */
498+
499+
500+
/* int4_mul_cash()
501+
* Multiply int4 by cash.
502+
*/
503+
Cash*
504+
int4_mul_cash(int4i,Cash*c)
505+
{
506+
return (cash_mul_int4(c,i));
507+
}/* int4_mul_cash() */
508+
509+
510+
/* cash_div_int4()
511+
* Divide cash by 4-byte integer.
512+
*
513+
* XXX Don't know if rounding or truncating is correct behavior.
514+
* Round for now. - tgl 97/04/15
515+
*/
516+
Cash*
517+
cash_div_int4(Cash*c,int4i)
518+
{
519+
Cash*result;
520+
521+
if (!PointerIsValid(c))
522+
return (NULL);
523+
524+
if (!PointerIsValid(result=PALLOCTYPE(Cash)))
525+
elog(WARN,"Memory allocation failed, can't divide cash",NULL);
526+
527+
if (i==0)
528+
elog(WARN,"cash_idiv: divide by 0 error");
529+
530+
*result=rint(*c /i);
531+
532+
return (result);
533+
}/* cash_div_int4() */
534+
535+
536+
/* cash_mul_int2()
537+
* Multiply cash by int2.
538+
*/
539+
Cash*
540+
cash_mul_int2(Cash*c,int2s)
541+
{
542+
Cash*result;
543+
544+
if (!PointerIsValid(c))
545+
return (NULL);
546+
547+
if (!PointerIsValid(result=PALLOCTYPE(Cash)))
548+
elog(WARN,"Memory allocation failed, can't multiply cash",NULL);
549+
550+
*result= ((s)* (*c));
551+
552+
return (result);
553+
}/* cash_mul_int2() */
554+
555+
556+
/* int2_mul_cash()
557+
* Multiply int2 by cash.
558+
*/
559+
Cash*
560+
int2_mul_cash(int2s,Cash*c)
561+
{
562+
return (cash_mul_int2(c,s));
563+
}/* int2_mul_cash() */
564+
565+
566+
/* cash_div_int2()
567+
* Divide cash by int2.
568+
*
569+
* XXX Don't know if rounding or truncating is correct behavior.
570+
* Round for now. - tgl 97/04/15
571+
*/
572+
Cash*
573+
cash_div_int2(Cash*c,int2s)
574+
{
575+
Cash*result;
576+
577+
if (!PointerIsValid(c))
578+
return (NULL);
579+
580+
if (!PointerIsValid(result=PALLOCTYPE(Cash)))
581+
elog(WARN,"Memory allocation failed, can't divide cash",NULL);
582+
583+
if (s==0)
584+
elog(WARN,"cash_div: divide by 0 error");
585+
586+
*result=rint(*c /s);
587+
588+
return (result);
589+
}/* cash_div_int2() */
413590

414591

415592
/* cashlarger()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp