ldecNumber

Check-in [6225bab0ea]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Integrate Asko's generalized Makefile. Add __concat to decimal numbers. Update doco and README.txt
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:6225bab0eadc5b1c4190538dff97aa64aef40392
User & Date: e@6e5be3b1-1950-f047-a965-c680c9cf6ecc 2006-10-02 20:00:51
Context
2007-01-17
04:55
Update to decNumber 3.37 Add random number generator Add pod documentation check-in: acd5876087 user: e@6e5be3b1-1950-f047-a965-c680c9cf6ecc tags: trunk
2006-10-02
20:00
Integrate Asko's generalized Makefile. Add __concat to decimal numbers. Update doco and README.txt check-in: 6225bab0ea user: e@6e5be3b1-1950-f047-a965-c680c9cf6ecc tags: trunk
2006-09-28
22:31
Add floor function and associated tests and doco. check-in: 655e4351ee user: e@6e5be3b1-1950-f047-a965-c680c9cf6ecc tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Makefile.

2
3
4
5
6
7
8

















9

10
11
12
13
14







15
16
17
18


























19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60


61
62
63
64
65
66
67
68
69
70
71
72
..
80
81
82
83
84
85
86

#
# Created September 3, 2006 by e
# This version of the Makefile has been used on WinXP with MinGW/MSYS
# Subversion is used for version control 
#   and generation of version info for headers and file names
# Be sure to "make install" before "make testall"


















# change these to reflect your Lua installation

LUA= /usr/local
LUAINC= $(LUA)/include
LUALIB= $(LUA)/lib
LUABIN= $(LUA)/bin
LUALUA= $(LUA)/lua








TMP=./tmp
DISTDIR=./archive



























# no need to change anything below here - HAH!
CFLAGS= $(INCS) $(DEFS) $(WARN) -O2 $(SHFLAGS)
#SHFLAGS= -fPIC
SHFLAGS=
WARN= -Wall #-ansi -pedantic -Wall
INCS= -I$(LUAINC) -IdecNumber
#LIBS= -L$(LUALIB) -llualib5 -llua5
LIBS= -L$(LUALIB) -llua51

MYNAME= decNumber
MYLIB= l$(MYNAME)
VER=$(shell svnversion -c . | sed 's/.*://')
TARFILE = $(DISTDIR)/$(MYLIB)-$(VER).tar.gz

OBJS= $(MYLIB).o decNumber/decNumber.o decNumber/decContext.o
#T= $(MYLIB).so
T= $(MYLIB).dll

TESTLIBS=test/lperformance.DLL

all: $T

$T:	version.h $(OBJS)
	$(CC) $(SHFLAGS) -o $@ -shared $(OBJS) $(LIBS)

$(MYLIB).o: version.h

version.h: vcheck

vcheck:
	SubWCRev `pwd` version.in version.h

test: $T
	cd test; $(LUABIN)/lua.exe ldecNumberUnitTest.lua
	cd test; $(LUABIN)/lua.exe ldecNumberThreadsTest.lua
	cd test; $(LUABIN)/lua.exe ldecNumberTestDriver.lua

# testall will only work on Windows unless you remove/rewrite performance tests

testall: $T $(TESTLIBS) test
	cd test; $(LUABIN)/lua.exe ldecNumberPerf.lua



test/lperformance.DLL:	test/lperformance.o
	$(CC) $(SHFLAGS) -o $@ -shared test/lperformance.o $(LIBS)

install:
	cp $T $(LUABIN)

clean:
	rm -f $(OBJS) $T core core.* a.out

td:
	touch $(MYLIB)-$(VER).tar.gz

................................................................................
	cp -p doc/ldecNumber.pdf $(TMP)/$(MYLIB)-$(VER)/doc
	echo 'Compressing...'
	tar -zcf $(TARFILE) -C $(TMP) $(MYLIB)-$(VER)
	rm -fr $(TMP)/$(MYLIB)-$(VER)
	echo 'Done.'

.PHONY: all vcheck test testall clean td dist install








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
|
<
<
<
<
>
>
>
>
>
>
>




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


<
<

|
<
|







|
<

|











|


|
|
|




|

>
>
|



|







 







>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28




29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67


68
69

70
71
72
73
74
75
76
77
78

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
...
125
126
127
128
129
130
131
132
#
# Created September 3, 2006 by e
# This version of the Makefile has been used on WinXP with MinGW/MSYS
# Subversion is used for version control 
#   and generation of version info for headers and file names
# Be sure to "make install" before "make testall"

#AK(30-Sep-06):
# - adopted for OS X (and generalized a bit while at it..)
# - adopted for pkg-config (as an alternative for manually giving the paths)

ifneq "$(shell pkg-config --version)" ""
  # automagic setup (OS X fink, Linux apt-get, ..)
  #
  LUAINC= $(shell pkg-config --cflags lua)
  LUALIB= $(shell pkg-config --libs lua)
  LUAEXE= lua
  #
  # Now, we actually want to _not_ push in stuff to the distro Lua CMOD directory,
  # way better to play within /usr/local/lib/lua/5.1/
  #
  #LUACMOD= $(shell pkg-config --variable=INSTALL_CMOD lua)
  LUACMOD= /usr/local/lib/lua/5.1/
else
  # manual setup (change these to reflect your Lua installation)
  #
  BASE= /usr/local




  LUAINC= -I$(BASE)/include
  LUALIB= -L$(BASE)/lib -llua51
  LUAEXE= $(BASE)/bin/lua.exe
#  LUACMOD= $(BASE)/lib/lua/5.1/
#  Windows' LUA_CDIR is the Lua executable's directory...
  LUACMOD= $(BASE)/bin
endif

TMP=./tmp
DISTDIR=./archive

# OS detection
#
SHFLAGS=-shared
VCHECK=
UNAME= $(shell uname)
ifeq "$(UNAME)" "Linux"
  _SO=so
  SHFLAGS= -fPIC
endif
ifneq "" "$(findstring BSD,$(UNAME))"
  _SO=so
endif
ifeq "$(UNAME)" "Darwin"
  _SO=bundle
  SHFLAGS= -bundle
endif
ifneq "" "$(findstring msys,$(OSTYPE))"		# 'msys'
  _SO=dll
  VCHECK=SubWCRev `pwd` version.in version.h
endif

ifndef _SO
  $(error $(UNAME))
  $(error Unknown OS)
endif

# no need to change anything below here - HAH!
CFLAGS= $(INCS) $(DEFS) $(WARN) -O2 $(SHFLAGS)


WARN= -Wall #-ansi -pedantic -Wall
INCS= $(LUAINC) -IdecNumber

LIBS= $(LUALIB)

MYNAME= decNumber
MYLIB= l$(MYNAME)
VER=$(shell svnversion -c . | sed 's/.*://')
TARFILE = $(DISTDIR)/$(MYLIB)-$(VER).tar.gz

OBJS= $(MYLIB).o decNumber/decNumber.o decNumber/decContext.o
T= $(MYLIB).$(_SO)


TESTLIBS=test/lperformance.$(_SO)

all: $T

$T:	version.h $(OBJS)
	$(CC) $(SHFLAGS) -o $@ -shared $(OBJS) $(LIBS)

$(MYLIB).o: version.h

version.h: vcheck

vcheck:
	$(VCHECK)

test: $T
	cd test; $(LUAEXE) ldecNumberUnitTest.lua
	cd test; $(LUAEXE) ldecNumberThreadsTest.lua
	cd test; $(LUAEXE) ldecNumberTestDriver.lua

# testall will only work on Windows unless you remove/rewrite performance tests

testall: $T $(TESTLIBS) test
	cd test; $(LUAEXE) ldecNumberPerf.lua

# Note: This is Windows specific anyways... :((((((
#
test/lperformance.$(_SO):	test/lperformance.o
	$(CC) $(SHFLAGS) -o $@ -shared test/lperformance.o $(LIBS)

install:
	cp $T $(LUACMOD)

clean:
	rm -f $(OBJS) $T core core.* a.out

td:
	touch $(MYLIB)-$(VER).tar.gz

................................................................................
	cp -p doc/ldecNumber.pdf $(TMP)/$(MYLIB)-$(VER)/doc
	echo 'Compressing...'
	tar -zcf $(TARFILE) -C $(TMP) $(MYLIB)-$(VER)
	rm -fr $(TMP)/$(MYLIB)-$(VER)
	echo 'Done.'

.PHONY: all vcheck test testall clean td dist install

Changes to README.txt.

1
2
3
4
5
6
7
8
9
10
..
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67





68
69
70
71
72
73
74
75
76
77
78
79
80
ldecNumber -- a Lua 5.1 wrapper for the decNumber Decimal Arithmetic package.

September 22, 2006

The Lua wrapper is
Copyright (c) 2006 Doug Currie, Londonderry, NH
All rights reserved.

The decNumber C library is
Copyright (c) 1995-2005 International Business Machines Corporation and others
................................................................................
doc/ldecNumber.pdf
doc/decnumber.pdf

Building the Lua module...

The wrapper and decNumber library are built as a monolithic Lua module.

The Makefile provided is written and tested with MinGW/MSYS on WindowsXP,
and with a Subversion repository.

It can probably be adapted quite easily for other platforms.
Basically, you must compile and link (with Lua) three files: 
  decNumber/decContext.c and .o
  decNumber/decNumber.c and .o
  ldecNumber.c and .o
There are no extenal dependencies other than Lua 5.1(.1)

If you are not working with the Subversion repository (which is presently
unlikely since it is on my local network), comment out the line

version.h: vcheck

in the Makefile.

The Makefile produces a shared library (DLL) that should be installed 
in Lua's loadable C module search path (package.cpath).

Makefile targets...

make

build the loadable C module ldecNumber.DLL

make vcheck

update version.h from a Subversion repository -- you will probably want 
to eliminate this target from Makefile dependencies; a version.h is 
included in the distribution to facilitate this

make install

copy the loadable C module to $(LUABIN)

make test

runs the tests; be sure to "make install" first!






make testall

does a "make test" followed by the Windows-only performance test

make clean

the usual

make dist

probably only useful as documentation for how I build the distribution

-=-


|







 







|
|

<
|





<
<
<
<
<
<
<
|






|
<
<
<
<
<
<



|





>
>
>
>
>













1
2
3
4
5
6
7
8
9
10
..
21
22
23
24
25
26
27
28
29
30

31
32
33
34
35
36







37
38
39
40
41
42
43
44






45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
ldecNumber -- a Lua 5.1 wrapper for the decNumber Decimal Arithmetic package.

October 2, 2006

The Lua wrapper is
Copyright (c) 2006 Doug Currie, Londonderry, NH
All rights reserved.

The decNumber C library is
Copyright (c) 1995-2005 International Business Machines Corporation and others
................................................................................
doc/ldecNumber.pdf
doc/decnumber.pdf

Building the Lua module...

The wrapper and decNumber library are built as a monolithic Lua module.

Thanks to Asko Kauppi the Makefile provided is written for multiple platforms,
and tested with MinGW/MSYS on WindowsXP, OS X, and with a Subversion repository.


Basically, the Makefile compiles and links (with Lua) three files: 
  decNumber/decContext.c and .o
  decNumber/decNumber.c and .o
  ldecNumber.c and .o
There are no extenal dependencies other than Lua 5.1(.1)








The Makefile produces a shared library (.so, .DLL) that should be installed 
in Lua's loadable C module search path (package.cpath).

Makefile targets...

make

build the loadable C module ldecNumber.{DLL|so}







make install

copy the loadable C module to $(LUACMOD)

make test

runs the tests; be sure to "make install" first!

make vcheck

update version.h from a Subversion repository -- you will not need to build 
this target; a version.h is included in the distribution

make testall

does a "make test" followed by the Windows-only performance test

make clean

the usual

make dist

probably only useful as documentation for how I build the distribution

-=-

Changes to doc/ldecNumber.odt.

cannot compute difference between binary files

Changes to ldecNumber.c.

437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
...
460
461
462
463
464
465
466
467
468
469
470
471
472
473





















474
475
476
477
478
479
480
...
693
694
695
696
697
698
699

700
701
702
703
704
705
706

DN_PR2(dn_eq,decNumberCompare,decNumberIsZero)
DN_PR2(dn_lt,decNumberCompare,decNumberIsNegative)
DN_PR2(dn_le,decNumberCompare,decNumberIsNegativeOrZero)

/* to string */

static int ldn_string (lua_State *L, char *(*sf)(const decNumber *, char *))
{
    char buf[128];
    decContext *dc = ldn_get_context (L);
    decNumber *dn = ldn_get (L, dc, 1);
    if ((dn->digits + 15) <= 128)
    {
        lua_pushstring (L, sf(dn, buf));
    }
    else
    {
        void *ud;
................................................................................
        (*f) (ud, dbuf, dn->digits + 15, 0);               // free
    }
    return 1;
}

static int dn_string (lua_State *L)
{
    return ldn_string (L, decNumberToString);
}

static int dn_engstring (lua_State *L)
{
    return ldn_string (L, decNumberToEngString);
}






















/* *********************** context methods ************************** */

/* Context must always be set correctly:                              */
/*                                                                    */
/*  digits   -- must be in the range 1 through 999999999              */
/*  emax     -- must be in the range 0 through 999999999              */
................................................................................
    { "__div",      dn_div    },
    { "__pow",      dn_pow    },
    { "__mod",      dn_mod    },
    { "__eq",       dn_eq     },
    { "__lt",       dn_lt     },
    { "__le",       dn_le     },
    { "__tostring", dn_string },

    
    { NULL,         NULL      }
};

static const luaL_reg dn_context_meta_lib[] =
{
    {"setdefault",       dn_ctx_set_default   },







|



|







 







|




|

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>







437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
...
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
...
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728

DN_PR2(dn_eq,decNumberCompare,decNumberIsZero)
DN_PR2(dn_lt,decNumberCompare,decNumberIsNegative)
DN_PR2(dn_le,decNumberCompare,decNumberIsNegativeOrZero)

/* to string */

static int ldn_string (lua_State *L, int x, char *(*sf)(const decNumber *, char *))
{
    char buf[128];
    decContext *dc = ldn_get_context (L);
    decNumber *dn = ldn_get (L, dc, x);
    if ((dn->digits + 15) <= 128)
    {
        lua_pushstring (L, sf(dn, buf));
    }
    else
    {
        void *ud;
................................................................................
        (*f) (ud, dbuf, dn->digits + 15, 0);               // free
    }
    return 1;
}

static int dn_string (lua_State *L)
{
    return ldn_string (L, 1, decNumberToString);
}

static int dn_engstring (lua_State *L)
{
    return ldn_string (L, 1, decNumberToEngString);
}

static int dn_concat (lua_State *L)
{
    if (lua_isstring (L,1))
    {
        lua_pushvalue (L,1);
        ldn_string (L, 2, decNumberToString);
    }
    else if (lua_isstring (L,2))
    {
        ldn_string (L, 1, decNumberToString);
        lua_pushvalue (L,2);
    }
    else
    {
        return luaL_error (L, "concat decNumber requires a string argument");
    }
    lua_concat (L,2);
    return 1;
}


/* *********************** context methods ************************** */

/* Context must always be set correctly:                              */
/*                                                                    */
/*  digits   -- must be in the range 1 through 999999999              */
/*  emax     -- must be in the range 0 through 999999999              */
................................................................................
    { "__div",      dn_div    },
    { "__pow",      dn_pow    },
    { "__mod",      dn_mod    },
    { "__eq",       dn_eq     },
    { "__lt",       dn_lt     },
    { "__le",       dn_le     },
    { "__tostring", dn_string },
    { "__concat",   dn_concat },
    
    { NULL,         NULL      }
};

static const luaL_reg dn_context_meta_lib[] =
{
    {"setdefault",       dn_ctx_set_default   },