Added *really* basic double to BCD conversion
This commit is contained in:
parent
7d18dbcd01
commit
1b99b96f54
5
Makefile
5
Makefile
|
@ -180,16 +180,15 @@ $(eval $(call make-obj-rule,$(src))))
|
|||
$(call qcmd,$(INST) -m 755 -d "$(IBINDIR)")
|
||||
$(call qcmd,tools/write-config \
|
||||
--name=$(NAME) --version=$(VERSION) --target="$(TARGET)" \
|
||||
--runlibs="$(RLIBS)" \
|
||||
--maintainer="$(MAINTAINER_NAME) <$(MAINTAINER_MAIL)>" \
|
||||
--incdir="$(OIINCDIR)/lib$(NAME)-$(VERSION)" --libdir="$(OILIBDIR)" \
|
||||
>"$(IBINDIR)/$(TARGET)lib$(NAME)-config" \
|
||||
&& chmod 755 "$(IBINDIR)/$(TARGET)lib$(NAME)-config")
|
||||
|
||||
$(call imsg,Installing the pkg-config configuration.)
|
||||
$(call qcmd,$(INST) -m 755 -d "$(IPKGDIR)")
|
||||
$(call qcmd,tools/write-pkg-config \
|
||||
--name=$(NAME) --version=$(VERSION) --runlibs="$(RLIBS)" \
|
||||
--name=$(NAME) --version=$(VERSION) \
|
||||
--deps="$(DEPS)" --deps.private="$(DEPS_PRIV)" \
|
||||
--description="$(DESCRIPTION)" \
|
||||
--incdir="$(OIINCDIR)/lib$(NAME)-$(VERSION)" --libdir="$(OILIBDIR)" \
|
||||
>"$(IPKGDIR)/lib$(NAME).pc" \
|
||||
|
|
|
@ -56,11 +56,10 @@
|
|||
ANAME := $(if $(FOR_WINDOWS),lib$(NAME).lib,lib$(NAME).a)
|
||||
ANAMES := lib$(NAME).lib lib$(NAME).a lib$(NAME).dll.a
|
||||
|
||||
# Runtime libs
|
||||
RLIBS := libfontcharacter
|
||||
|
||||
# Compilation time libs
|
||||
LIBS := zlib $(RLIBS)
|
||||
# Libs
|
||||
DEPS := libfontcharacter
|
||||
DEPS_PRIV := zlib
|
||||
ALLDEPS := $(DEPS) $(DEPS_PRIV)
|
||||
|
||||
#******************************************************************************#
|
||||
# Binary utilities #
|
||||
|
@ -85,7 +84,7 @@ endif
|
|||
CFLAGS := -I $(INCDIR) $(CWARN) -std=gnu11 \
|
||||
$(if $(STATIC),,-fPIC) $(if $(OPTIMIZE_SIZE),-Os,-O2) \
|
||||
-D LOGLEVEL="ll_$(LOG_LEVEL)" \
|
||||
$(shell $(PKGCONFIG) --cflags $(LIBS) 2>/dev/null) \
|
||||
$(shell $(PKGCONFIG) --cflags $(ALLDEPS) 2>/dev/null) \
|
||||
$(CMOREFLAGS)
|
||||
|
||||
# Linker
|
||||
|
@ -97,7 +96,7 @@ endif
|
|||
-Wl,-z,relro -Wl,-z,combreloc -Wl,-z,defs)
|
||||
# - Linker flags
|
||||
LDFLAGS := $(if $(STATIC),,-shared) \
|
||||
$(shell $(PKGCONFIG) --libs $(LIBS) 2>/dev/null) \
|
||||
$(shell $(PKGCONFIG) --libs $(ALLDEPS) 2>/dev/null) -lm \
|
||||
$(if $(FOR_WINDOWS),$(LDFLAGS_Windows),$(LDFLAGS_Linux)) \
|
||||
$(LDMOREFLAGS)
|
||||
|
||||
|
|
17
README.md
17
README.md
|
@ -15,14 +15,15 @@ Side note : the library might work with older versions of these dependencies,
|
|||
I took these as a reference because these are the ones I work with.
|
||||
|
||||
### Making-only dependencies
|
||||
| Name | Version |
|
||||
| -------------------------------------------------- | -------- |
|
||||
| [make](https://www.gnu.org/software/make/) | >= 4.0 |
|
||||
| [gcc](https://gcc.gnu.org/) | >= 4.9 |
|
||||
| [binutils](https://www.gnu.org/software/binutils/) | >= 2.25 |
|
||||
| [asciidoc](http://asciidoc.org/) | >= 8.6.9 |
|
||||
| [gzip](https://www.gnu.org/software/gzip/) | >= 1.6 |
|
||||
| [python3](https://www.python.org/) | >= 3.5 |
|
||||
| Name | Version |
|
||||
| ------------------------------------------------------------------- | -------- |
|
||||
| [make](https://www.gnu.org/software/make/) | >= 4.0 |
|
||||
| [gcc](https://gcc.gnu.org/) | >= 4.9 |
|
||||
| [binutils](https://www.gnu.org/software/binutils/) | >= 2.25 |
|
||||
| [asciidoc](http://asciidoc.org/) | >= 8.6.9 |
|
||||
| [gzip](https://www.gnu.org/software/gzip/) | >= 1.6 |
|
||||
| [python3](https://www.python.org/) | >= 3.5 |
|
||||
| [pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/) | any |
|
||||
|
||||
### Runtime dependencies
|
||||
| Name | Version |
|
||||
|
|
|
@ -122,6 +122,10 @@ void g1m_bcd_tomcs(const g1m_bcd_t *bcd, mcs_bcd_t *raw);
|
|||
int g1m_bcd_fromcas(const cas_bcd_t *raw, g1m_bcd_t *bcd);
|
||||
void g1m_bcd_tocas(const g1m_bcd_t *bcd, cas_bcd_t *raw);
|
||||
|
||||
/* From and to C-double */
|
||||
void g1m_bcd_fromdouble(double dbl, g1m_bcd_t *bcd);
|
||||
double g1m_bcd_todouble(const g1m_bcd_t *bcd);
|
||||
|
||||
/* Make a string out of a BCD */
|
||||
size_t g1m_bcdtoa(const g1m_bcd_t *bcd, char *buf, size_t len);
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
* ************************************************************************** */
|
||||
#ifndef LIBG1M_FORMAT_CASEMUL_H
|
||||
# define LIBG1M_FORMAT_CASEMUL_H
|
||||
# include <libg1m/bcd.h>
|
||||
# pragma pack(1)
|
||||
|
||||
/* Casemul files are made of an overall header, a source part and an
|
||||
|
@ -174,7 +175,9 @@ struct casemul_mtrx_header {
|
|||
uint32_t lines, columns;
|
||||
};
|
||||
|
||||
/* TODO: describe the matrix format more precisely. */
|
||||
/* Then it's simply a tab of `lines*columns` `double` numbers,
|
||||
* ordered by lines (y). They are the real parts, as the numbers in those
|
||||
* matrixes have got no imaginary parts. */
|
||||
/* ************************************************************************** */
|
||||
/* List */
|
||||
/* ************************************************************************** */
|
||||
|
@ -186,7 +189,8 @@ struct casemul_list_header {
|
|||
uint32_t lines;
|
||||
};
|
||||
|
||||
/* TODO: describe the list format more precisely. */
|
||||
/* Then it's simply a tab of `lines` `double` numbers.
|
||||
* The numbers in these have no imaginary parts. */
|
||||
|
||||
# pragma pack()
|
||||
#endif /* LIBG1M_FORMAT_CASEMUL_H */
|
||||
|
|
|
@ -45,11 +45,12 @@
|
|||
# define ll_none 4
|
||||
|
||||
/* Macros */
|
||||
# define log(P, S, ...) fprintf(stderr, P "%s: " S "\n", __FUNCTION__, ##__VA_ARGS__)
|
||||
# define g1m_log(P, S, ...) \
|
||||
fprintf(stderr, P "%s: " S "\n", __FUNCTION__, ##__VA_ARGS__)
|
||||
# define logm(S, M, N) g1m_log_mem(S, M, N)
|
||||
|
||||
# if LOGLEVEL <= ll_info
|
||||
# define log_info(S, ...) log("[libg1m info] ", S, ##__VA_ARGS__)
|
||||
# define log_info(S, ...) g1m_log("[libg1m info] ", S, ##__VA_ARGS__)
|
||||
# define logm_info(M, N) logm("[libg1m info] ", M, N)
|
||||
# else
|
||||
# define log_info(S, ...)
|
||||
|
@ -57,7 +58,7 @@
|
|||
# endif
|
||||
|
||||
# if LOGLEVEL <= ll_warn
|
||||
# define log_warn(S, ...) log("[libg1m warn] ", S, ##__VA_ARGS__)
|
||||
# define log_warn(S, ...) g1m_log("[libg1m warn] ", S, ##__VA_ARGS__)
|
||||
# define logm_warn(M, N) logm("[libg1m warn] ", M, N)
|
||||
# else
|
||||
# define log_warn(S, ...)
|
||||
|
@ -65,13 +66,13 @@
|
|||
# endif
|
||||
|
||||
# if LOGLEVEL <= ll_error
|
||||
# define log_error(S, ...) log("[libg1m error] ", S, ##__VA_ARGS__)
|
||||
# define log_error(S, ...) g1m_log("[libg1m error] ", S, ##__VA_ARGS__)
|
||||
# else
|
||||
# define log_error(S, ...)
|
||||
# endif
|
||||
|
||||
# if LOGLEVEL <= ll_fatal
|
||||
# define log_fatal(S, ...) log("[libg1m fatal] ", S, ##__VA_ARGS__)
|
||||
# define log_fatal(S, ...) g1m_log("[libg1m fatal] ", S, ##__VA_ARGS__)
|
||||
# else
|
||||
# define log_fatal(S, ...)
|
||||
# endif
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
/* *****************************************************************************
|
||||
* bcd/double.c -- make a libg1m BCD out of a double.
|
||||
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libg1m.
|
||||
* libg1m is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 3.0 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* libg1m is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with libg1m; if not, see <http://www.gnu.org/licenses/>.
|
||||
* ************************************************************************** */
|
||||
#include <libg1m/internals.h>
|
||||
#include <math.h>
|
||||
|
||||
/**
|
||||
* g1m_bcd_fromdouble:
|
||||
* Make a libg1m BCD number out of a C-double.
|
||||
*
|
||||
* @arg dbl the double.
|
||||
* @arg bcd the BCD to set.
|
||||
*/
|
||||
|
||||
void g1m_bcd_fromdouble(double dbl, g1m_bcd_t *bcd)
|
||||
{
|
||||
/* check if is negative */
|
||||
int neg = 0;
|
||||
if (dbl < 0) {
|
||||
neg = 1;
|
||||
dbl = -dbl;
|
||||
}
|
||||
|
||||
/* check the exponent, normalize the number */
|
||||
int exp = 1;
|
||||
while (dbl >= 10) {
|
||||
exp++;
|
||||
dbl /= 10;
|
||||
}
|
||||
while (dbl < 1) {
|
||||
exp--;
|
||||
dbl *= 10;
|
||||
}
|
||||
|
||||
/* get the mantissa */
|
||||
for (int i = 0; i < 15; i++) {
|
||||
double work = floor(dbl);
|
||||
bcd->mant[i] = (int)work;
|
||||
dbl = (dbl - work) * 10;
|
||||
}
|
||||
|
||||
/* set the flags */
|
||||
bcd->flags = g1m_make_bcdflags(0, neg, 15);
|
||||
bcd->exp = exp;
|
||||
}
|
||||
|
||||
/**
|
||||
* g1m_bcd_todouble:
|
||||
* Make a C-double out of a libg1m BCD number.
|
||||
*
|
||||
* @arg bcd the BCD to convert.
|
||||
* @return the double.
|
||||
*/
|
||||
|
||||
double g1m_bcd_todouble(const g1m_bcd_t *bcd)
|
||||
{
|
||||
/* TODO */
|
||||
return (0);
|
||||
}
|
|
@ -9,23 +9,18 @@ version="<unknown version>"
|
|||
# Maintainer
|
||||
maintainer="Some unknown guy <anon@localhost>"
|
||||
|
||||
# Directories
|
||||
libdir=''
|
||||
incdir=''
|
||||
|
||||
#******************************************************************************#
|
||||
# Read arguments #
|
||||
#******************************************************************************#
|
||||
for arg ; do case "$arg" in
|
||||
--name=*) name="${arg#*=}" ;;
|
||||
--target=*) target="${arg#*=}" ;;
|
||||
--runlibs=*) runlibs="${arg#*=}" ;;
|
||||
--version=*) version="${arg#*=}" ;;
|
||||
--maintainer=*) maintainer="${arg#*=}" ;;
|
||||
--libdir=*) libdir="${arg#*=}" ;;
|
||||
--incdir=*) incdir="${arg#*=}" ;;
|
||||
esac; done
|
||||
|
||||
[ "$target" ] && target="${target}-"
|
||||
|
||||
#******************************************************************************#
|
||||
# Write result #
|
||||
#******************************************************************************#
|
||||
|
@ -76,15 +71,11 @@ for arg ; do case "\$arg" in
|
|||
esac; done
|
||||
|
||||
# Put
|
||||
if [ \$put_cflags ]; then
|
||||
echo "-I$incdir"
|
||||
for rdep in ${runlibs}; do ${target}\${rdep}-config --cflags; done
|
||||
fi
|
||||
if [ \$put_libs ]; then
|
||||
echo "-L$libdir -l$name"
|
||||
for rdep in ${runlibs}; do ${target}\${rdep}-config --libs; done
|
||||
fi
|
||||
opt=""
|
||||
[ \$put_cflags\$put_libs ] || usage
|
||||
[ \$put_cflags ] && opt+="--cflags "
|
||||
[ \$put_libs ] && opt+="--libs "
|
||||
${target}pkg-config ${runlibs} \$opt
|
||||
|
||||
# End of file
|
||||
_EOF
|
||||
|
|
|
@ -18,11 +18,11 @@ for arg ; do case "$arg" in
|
|||
--name=*) name="${arg#*=}" ;;
|
||||
--description=*) description="${arg#*=}" ;;
|
||||
--version=*) version="${arg#*=}" ;;
|
||||
--runlibs=*) runlibs="${arg#*=}" ;;
|
||||
--deps=*) deps="${arg#*=}" ;;
|
||||
--deps.private=*) privdeps="${arg#*=}" ;;
|
||||
--libdir=*) libdir="${arg#*=}" ;;
|
||||
--incdir=*) incdir="${arg#*=}" ;;
|
||||
esac; done
|
||||
|
||||
#******************************************************************************#
|
||||
# Write result #
|
||||
#******************************************************************************#
|
||||
|
@ -33,7 +33,9 @@ libdir=$libdir
|
|||
Name: lib$name
|
||||
Description: $description
|
||||
Version: $version
|
||||
Requires: $runlibs
|
||||
Requires: $deps
|
||||
Requires.private: $privdeps
|
||||
Libs: -L\${libdir} -l$name
|
||||
Libs.private: -lm
|
||||
Cflags: -I\${includedir}
|
||||
EOF
|
||||
|
|
Reference in New Issue