Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precise fsum #2513

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
713ef9f
std.internal.math.summation added
9il Sep 14, 2014
d8fcdb4
merge master
9il Feb 8, 2015
331806c
merge master
9il Feb 8, 2015
633945f
Merge branch 'sum' of https://github.com/9il/phobos into sum
9il Feb 8, 2015
f30ec34
fix comments
9il Feb 8, 2015
8c9a2d2
add std.numeric package
9il Feb 8, 2015
c12a3df
fix *.mak files
9il Feb 8, 2015
ca3c563
fix posix.mak
9il Feb 8, 2015
ca20fd7
fix posix.mak
9il Feb 8, 2015
5dcc882
fix posix.mak
9il Feb 8, 2015
d511ea4
update code
9il Feb 8, 2015
da35310
fix typo
9il Feb 8, 2015
fbec67d
fix typo
9il Feb 8, 2015
86e86e3
fix spaces
9il Feb 8, 2015
dece67f
fix comments
9il Feb 8, 2015
b6fe9e4
remove blank lines
9il Feb 8, 2015
e888182
remove debug info
9il Feb 8, 2015
d48baf6
style fix
9il Feb 8, 2015
0bb19a6
minor fixes
9il Feb 8, 2015
bbfc8ab
move sumOfLog2s
9il Feb 8, 2015
ed82569
update headers
9il Feb 8, 2015
ad0cb3d
fix std.math imports
9il Feb 9, 2015
bf7d32f
update docs
9il Feb 9, 2015
3d7dd5b
remove spaces
9il Feb 9, 2015
28c52b1
remove commented code
9il Feb 9, 2015
5aa11cb
fix fabs, add bug workaround
9il Feb 9, 2015
4cffbfe
remove std.math.fabs usage
9il Feb 9, 2015
50796cf
comment code
9il Feb 9, 2015
c8aecb3
Merge remote-tracking branch 'upstream/master' into sum
9il Feb 14, 2015
c8b937d
update math imports
9il Feb 14, 2015
02198aa
minor fix
9il Feb 14, 2015
54196d5
workaround
9il Feb 14, 2015
728ce84
ICE bug workaround
9il Feb 14, 2015
c5043c2
fix module name
9il Feb 14, 2015
8c8c8c1
dmd bug workaround
9il Feb 14, 2015
6fd02c9
fix module name
9il Feb 14, 2015
8ff88a4
dmd bug workaround
9il Feb 14, 2015
4d97c13
fix module name
9il Feb 14, 2015
e5c05ff
std.math workaround
9il Feb 14, 2015
3976f2b
move unittest
9il Feb 14, 2015
31772b6
fix return behaviour
9il Feb 16, 2015
b9c47c7
workaround for Issue 13474
9il Feb 16, 2015
4eb2150
add comment
9il Feb 16, 2015
2218919
fix header name
9il Feb 16, 2015
0764837
remove changes in std.math
9il Feb 16, 2015
3c111b7
fix unittest
9il Feb 16, 2015
9c38dec
update unittest
9il Feb 16, 2015
27e377c
update unittest
9il Feb 16, 2015
8c8386c
pow bug workaround
9il Feb 16, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions posix.mak
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ DOCSRC = ../dlang.org
WEBSITE_DIR = ../web
DOC_OUTPUT_DIR = $(WEBSITE_DIR)/phobos-prerelease
BIGDOC_OUTPUT_DIR = /tmp
SRC_DOCUMENTABLES = index.d $(addsuffix .d,$(STD_MODULES) $(STD_NET_MODULES) $(STD_DIGEST_MODULES) $(STD_CONTAINER_MODULES) $(STD_RANGE_MODULES) $(STD_ALGO_MODULES) std/regex/package $(EXTRA_DOCUMENTABLES) $(STD_LOGGER_MODULES))
SRC_DOCUMENTABLES = index.d $(addsuffix .d,$(STD_MODULES) $(STD_NET_MODULES) $(STD_DIGEST_MODULES) $(STD_CONTAINER_MODULES) $(STD_RANGE_MODULES) $(STD_ALGO_MODULES) std/regex/package $(EXTRA_DOCUMENTABLES) $(STD_LOGGER_MODULES) $(STD_NUMERIC_MODULES))
STDDOC = $(DOCSRC)/html.ddoc $(DOCSRC)/dlang.org.ddoc $(DOCSRC)/std_navbar-prerelease.ddoc $(DOCSRC)/std.ddoc $(DOCSRC)/macros.ddoc
BIGSTDDOC = $(DOCSRC)/std_consolidated.ddoc $(DOCSRC)/macros.ddoc
# Set DDOC, the documentation generator
Expand Down Expand Up @@ -186,7 +186,7 @@ STD_MODULES = $(addprefix std/, array ascii base64 bigint \
bitmanip compiler complex concurrency conv \
cstream csv datetime demangle encoding exception \
file format functional getopt json math mathspecial \
metastrings mmfile numeric outbuffer parallelism path \
metastrings mmfile outbuffer parallelism path \
process random signals socket socketstream \
stdint stdio stdiobase stream string syserror system traits \
typecons typetuple uni uri utf uuid variant xml zip zlib)
Expand All @@ -209,6 +209,8 @@ STD_DIGEST_MODULES = $(addprefix std/digest/, digest crc md ripemd sha)
STD_CONTAINER_MODULES = $(addprefix std/container/, package array \
binaryheap dlist rbtree slist util)

STD_NUMERIC_MODULES = $(addprefix std/numeric/, package summation)

# OS-specific D modules
EXTRA_MODULES_LINUX := $(addprefix std/c/linux/, linux socket)
EXTRA_MODULES_OSX := $(addprefix std/c/osx/, socket)
Expand Down Expand Up @@ -236,7 +238,8 @@ EXTRA_MODULES += $(EXTRA_DOCUMENTABLES) $(addprefix \
# Aggregate all D modules relevant to this build
D_MODULES = $(STD_MODULES) $(EXTRA_MODULES) $(STD_NET_MODULES) \
$(STD_DIGEST_MODULES) $(STD_CONTAINER_MODULES) $(STD_REGEX_MODULES) \
$(STD_RANGE_MODULES) $(STD_ALGO_MODULES) $(STD_LOGGER_MODULES)
$(STD_RANGE_MODULES) $(STD_ALGO_MODULES) $(STD_LOGGER_MODULES) \
$(STD_NUMERIC_MODULES)

# Add the .d suffix to the module names
D_FILES = $(addsuffix .d,$(D_MODULES))
Expand Down Expand Up @@ -442,6 +445,9 @@ $(DOC_OUTPUT_DIR)/std_algorithm_%.html : std/algorithm/%.d $(STDDOC)
$(DOC_OUTPUT_DIR)/std_range_%.html : std/range/%.d $(STDDOC)
$(DDOC) project.ddoc $(STDDOC) -Df$@ $<

$(DOC_OUTPUT_DIR)/std_numeric_%.html : std/numeric/%.d $(STDDOC)
$(DDOC) project.ddoc $(STDDOC) -Df$@ $<

$(DOC_OUTPUT_DIR)/std_regex_%.html : std/regex/%.d $(STDDOC)
$(DDOC) project.ddoc $(STDDOC) -Df$@ $<

Expand Down
45 changes: 6 additions & 39 deletions std/numeric.d → std/numeric/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Distributed under the Boost Software License, Version 1.0.
*/
module std.numeric;

public import std.numeric.summation;

import std.complex;
import std.exception;
import std.math;
Expand Down Expand Up @@ -812,6 +814,7 @@ T findRoot(T, DF, DT)(scope DF f, in T a, in T b,
is(typeof(f(T.init)) == R, R) && isFloatingPoint!R
)
{
import std.math : fabs; // FIXME
auto r = findRoot(f, a, b, f(a), f(b), tolerance);
// Return the first value if it is smaller or NaN
return !(fabs(r[2]) > fabs(r[3])) ? r[0] : r[1];
Expand Down Expand Up @@ -870,6 +873,8 @@ in
}
body
{
import std.math : fabs; // FIXME

// Author: Don Clugston. This code is (heavily) modified from TOMS748
// (www.netlib.org). The changes to improve the worst-cast performance are
// entirely original.
Expand Down Expand Up @@ -1583,6 +1588,7 @@ unittest
}
}


/**
Normalizes values in $(D range) by multiplying each element with a
number chosen such that values sum up to $(D sum). If elements in $(D
Expand Down Expand Up @@ -1646,45 +1652,6 @@ unittest
assert(a == [ 0.5, 0.5 ]);
}

/**
Computes accurate sum of binary logarithms of input range $(D r).
*/
ElementType!Range sumOfLog2s(Range)(Range r)
if (isInputRange!Range && isFloatingPoint!(ElementType!Range))
{
long exp = 0;
Unqual!(typeof(return)) x = 1;
foreach (e; r)
{
if (e < 0)
return typeof(return).nan;
int lexp = void;
x *= frexp(e, lexp);
exp += lexp;
if (x < 0.5)
{
x *= 2;
exp--;
}
}
return exp + log2(x);
}

///
unittest
{
assert(sumOfLog2s(new double[0]) == 0);
assert(sumOfLog2s([0.0L]) == -real.infinity);
assert(sumOfLog2s([-0.0L]) == -real.infinity);
assert(sumOfLog2s([2.0L]) == 1);
assert(sumOfLog2s([-2.0L]).isNaN());
assert(sumOfLog2s([real.nan]).isNaN());
assert(sumOfLog2s([-real.nan]).isNaN());
assert(sumOfLog2s([real.infinity]) == real.infinity);
assert(sumOfLog2s([-real.infinity]).isNaN());
assert(sumOfLog2s([ 0.25, 0.25, 0.25, 0.125 ]) == -9);
}

/**
Computes $(LUCKY _entropy) of input range $(D r) in bits. This
function assumes (without checking) that the values in $(D r) are all
Expand Down