Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 221d729

Browse files
committed
Here is a bug fix and some spelling changes for the complex number tutorial
code. I have also written a complete complex number package based on this tutorial; I will submit this as a contribution soon. Is there a particular format for contributed tar files? I have a C source file, two SQL files, and a Makefile. Thomas Lockhart
1 parent cb6cb77 commit 221d729

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/tutorial/C-code/complex.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ int4
113113
complex_abs_cmp(Complex *a, Complex *b)
114114
{
115115
double amag = Mag(a), bmag = Mag(b);
116-
if (a < b)
116+
if (amag < bmag)
117117
return -1;
118-
else if (a > b)
118+
else if (amag > bmag)
119119
return 1;
120120
else
121121
return 0;

src/tutorial/complex.source

+8-7
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
--
33
-- complex.sql-
44
-- This file shows how to create a new user-defined type and how to
5-
-- use them.
5+
-- use this new type.
66
--
77
--
88
-- Copyright (c) 1994, Regents of the University of California
99
--
10-
-- $Id: complex.source,v 1.1.1.1 1996/07/09 06:22:34 scrappy Exp $
10+
-- $Id: complex.source,v 1.2 1996/12/28 02:22:07 momjian Exp $
1111
--
1212
---------------------------------------------------------------------------
1313

@@ -105,7 +105,7 @@ SELECT a + '(1.0,1.0)'::complex AS aa,
105105

106106
-----------------------------
107107
-- Creating aggregate functions
108-
-- you can also define aggregate functions. The syntax is some what
108+
-- you can also define aggregate functions. The syntax is somewhat
109109
-- cryptic but the idea is to express the aggregate in terms of state
110110
-- transition functions.
111111
-----------------------------
@@ -122,8 +122,8 @@ SELECT complex_sum(a) FROM test_complex;
122122

123123
-------------------------------------------------------------------------------
124124
-- ATTENTION! ATTENTION! ATTENTION! --
125-
-- YOU MAY SKIP THE SECTION BELOW ON INTERFACING WITH INDICIES. YOU DON'T --
126-
-- NEED THE FOLLOWING IF YOU DON'T USE INDICIES WITH NEW DATA TYPES. --
125+
-- YOU MAY SKIP THE SECTION BELOW ON INTERFACING WITH INDICES. YOU DON'T --
126+
-- NEED THE FOLLOWING IF YOU DON'T USE INDICES WITH NEW DATA TYPES. --
127127
-------------------------------------------------------------------------------
128128

129129
SELECT 'READ ABOVE!' AS STOP;
@@ -239,7 +239,8 @@ INSERT INTO pg_amproc (amid, amopclaid, amproc, amprocnum)
239239
and proname = 'complex_abs_cmp';
240240

241241
-- now, we can define a btree index on complex types. First, let's populate
242-
-- the table (THIS DOESN'T ACTUALLY WORK. YOU NEED MANY MORE TUPLES.)
242+
-- the table. Note that postgres needs many more tuples to start using the
243+
-- btree index during selects.
243244
INSERT INTO test_complex VALUES ('(56.0,-22.5)', '(-43.2,-0.07)')
244245
INSERT INTO test_complex VALUES ('(-91.9,33.6)', '(8.6,3.0)');
245246

@@ -248,4 +249,4 @@ CREATE INDEX test_cplx_ind ON test_complex
248249

249250
SELECT * from test_complex where a = '(56.0,-22.5)';
250251
SELECT * from test_complex where a < '(56.0,-22.5)';
251-
SELECT * from test_complex where a > '(56.0,-22.5)';
252+
SELECT * from test_complex where a > '(56.0,-22.5)';

0 commit comments

Comments
 (0)