Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
59847461
Commit
59847461
authored
Sep 20, 1997
by
Thomas G. Lockhart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Include functions for integer/money arithmetic.
parent
eba607d8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
186 additions
and
9 deletions
+186
-9
src/backend/utils/adt/cash.c
src/backend/utils/adt/cash.c
+186
-9
No files found.
src/backend/utils/adt/cash.c
View file @
59847461
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
* workings can be found in the book "Software Solutions in C" by
* workings can be found in the book "Software Solutions in C" by
* Dale Schumacher, Academic Press, ISBN: 0-12-632360-7.
* Dale Schumacher, Academic Press, ISBN: 0-12-632360-7.
*
*
* $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.1
5 1997/09/18 20:22:12 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.1
6 1997/09/20 16:15:34 thomas
Exp $
*/
*/
#include <stdio.h>
#include <stdio.h>
...
@@ -366,11 +366,11 @@ cash_mi(Cash *c1, Cash *c2)
...
@@ -366,11 +366,11 @@ cash_mi(Cash *c1, Cash *c2)
}
/* cash_mi() */
}
/* cash_mi() */
/* cash_mul()
/* cash_mul
_flt8
()
* Multiply cash by float
ing point number
.
* Multiply cash by float
8
.
*/
*/
Cash
*
Cash
*
cash_mul
(
Cash
*
c
,
float8
*
f
)
cash_mul
_flt8
(
Cash
*
c
,
float8
*
f
)
{
{
Cash
*
result
;
Cash
*
result
;
...
@@ -383,17 +383,27 @@ cash_mul(Cash *c, float8 *f)
...
@@ -383,17 +383,27 @@ cash_mul(Cash *c, float8 *f)
*
result
=
((
*
f
)
*
(
*
c
));
*
result
=
((
*
f
)
*
(
*
c
));
return
(
result
);
return
(
result
);
}
/* cash_mul() */
}
/* cash_mul
_flt8
() */
/* cash_div()
/* flt8_mul_cash()
* Divide cash by floating point number.
* Multiply float8 by cash.
*/
Cash
*
flt8_mul_cash
(
float8
*
f
,
Cash
*
c
)
{
return
(
cash_mul_flt8
(
c
,
f
));
}
/* flt8_mul_cash() */
/* cash_div_flt8()
* Divide cash by float8.
*
*
* XXX Don't know if rounding or truncating is correct behavior.
* XXX Don't know if rounding or truncating is correct behavior.
* Round for now. - tgl 97/04/15
* Round for now. - tgl 97/04/15
*/
*/
Cash
*
Cash
*
cash_div
(
Cash
*
c
,
float8
*
f
)
cash_div
_flt8
(
Cash
*
c
,
float8
*
f
)
{
{
Cash
*
result
;
Cash
*
result
;
...
@@ -409,7 +419,174 @@ cash_div(Cash *c, float8 *f)
...
@@ -409,7 +419,174 @@ cash_div(Cash *c, float8 *f)
*
result
=
rint
(
*
c
/
*
f
);
*
result
=
rint
(
*
c
/
*
f
);
return
(
result
);
return
(
result
);
}
/* cash_div() */
}
/* cash_div_flt8() */
/* cash_mul_flt4()
* Multiply cash by float4.
*/
Cash
*
cash_mul_flt4
(
Cash
*
c
,
float4
*
f
)
{
Cash
*
result
;
if
(
!
PointerIsValid
(
f
)
||
!
PointerIsValid
(
c
))
return
(
NULL
);
if
(
!
PointerIsValid
(
result
=
PALLOCTYPE
(
Cash
)))
elog
(
WARN
,
"Memory allocation failed, can't multiply cash"
,
NULL
);
*
result
=
((
*
f
)
*
(
*
c
));
return
(
result
);
}
/* cash_mul_flt4() */
/* flt4_mul_cash()
* Multiply float4 by float4.
*/
Cash
*
flt4_mul_cash
(
float4
*
f
,
Cash
*
c
)
{
return
(
cash_mul_flt4
(
c
,
f
));
}
/* flt4_mul_cash() */
/* cash_div_flt4()
* Divide cash by float4.
*
* XXX Don't know if rounding or truncating is correct behavior.
* Round for now. - tgl 97/04/15
*/
Cash
*
cash_div_flt4
(
Cash
*
c
,
float4
*
f
)
{
Cash
*
result
;
if
(
!
PointerIsValid
(
f
)
||
!
PointerIsValid
(
c
))
return
(
NULL
);
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
);
}
/* cash_div_flt4() */
/* cash_mul_int4()
* Multiply cash by int4.
*/
Cash
*
cash_mul_int4
(
Cash
*
c
,
int4
i
)
{
Cash
*
result
;
if
(
!
PointerIsValid
(
c
))
return
(
NULL
);
if
(
!
PointerIsValid
(
result
=
PALLOCTYPE
(
Cash
)))
elog
(
WARN
,
"Memory allocation failed, can't multiply cash"
,
NULL
);
*
result
=
((
i
)
*
(
*
c
));
return
(
result
);
}
/* cash_mul_int4() */
/* int4_mul_cash()
* Multiply int4 by cash.
*/
Cash
*
int4_mul_cash
(
int4
i
,
Cash
*
c
)
{
return
(
cash_mul_int4
(
c
,
i
));
}
/* int4_mul_cash() */
/* cash_div_int4()
* Divide cash by 4-byte integer.
*
* XXX Don't know if rounding or truncating is correct behavior.
* Round for now. - tgl 97/04/15
*/
Cash
*
cash_div_int4
(
Cash
*
c
,
int4
i
)
{
Cash
*
result
;
if
(
!
PointerIsValid
(
c
))
return
(
NULL
);
if
(
!
PointerIsValid
(
result
=
PALLOCTYPE
(
Cash
)))
elog
(
WARN
,
"Memory allocation failed, can't divide cash"
,
NULL
);
if
(
i
==
0
)
elog
(
WARN
,
"cash_idiv: divide by 0 error"
);
*
result
=
rint
(
*
c
/
i
);
return
(
result
);
}
/* cash_div_int4() */
/* cash_mul_int2()
* Multiply cash by int2.
*/
Cash
*
cash_mul_int2
(
Cash
*
c
,
int2
s
)
{
Cash
*
result
;
if
(
!
PointerIsValid
(
c
))
return
(
NULL
);
if
(
!
PointerIsValid
(
result
=
PALLOCTYPE
(
Cash
)))
elog
(
WARN
,
"Memory allocation failed, can't multiply cash"
,
NULL
);
*
result
=
((
s
)
*
(
*
c
));
return
(
result
);
}
/* cash_mul_int2() */
/* int2_mul_cash()
* Multiply int2 by cash.
*/
Cash
*
int2_mul_cash
(
int2
s
,
Cash
*
c
)
{
return
(
cash_mul_int2
(
c
,
s
));
}
/* int2_mul_cash() */
/* cash_div_int2()
* Divide cash by int2.
*
* XXX Don't know if rounding or truncating is correct behavior.
* Round for now. - tgl 97/04/15
*/
Cash
*
cash_div_int2
(
Cash
*
c
,
int2
s
)
{
Cash
*
result
;
if
(
!
PointerIsValid
(
c
))
return
(
NULL
);
if
(
!
PointerIsValid
(
result
=
PALLOCTYPE
(
Cash
)))
elog
(
WARN
,
"Memory allocation failed, can't divide cash"
,
NULL
);
if
(
s
==
0
)
elog
(
WARN
,
"cash_div: divide by 0 error"
);
*
result
=
rint
(
*
c
/
s
);
return
(
result
);
}
/* cash_div_int2() */
/* cashlarger()
/* cashlarger()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment