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

More robust fenv_constants #19384

Merged
merged 1 commit into from
Nov 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion base/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/pcre_h.jl
/errno_h.jl
/build_h.jl
/fenv_constants.jl
/file_constants.jl
/uv_constants.jl
/version_git.jl
Expand Down
7 changes: 2 additions & 5 deletions base/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ else
CPP_STDOUT := $(CPP) -E
endif

all: $(addprefix $(BUILDDIR)/,pcre_h.jl errno_h.jl build_h.jl.phony fenv_constants.jl file_constants.jl uv_constants.jl version_git.jl.phony)
all: $(addprefix $(BUILDDIR)/,pcre_h.jl errno_h.jl build_h.jl.phony file_constants.jl uv_constants.jl version_git.jl.phony)

PCRE_CONST := 0x[0-9a-fA-F]+|[0-9]+
ifeq ($(USE_SYSTEM_PCRE), 1)
Expand All @@ -27,9 +27,6 @@ $(BUILDDIR)/pcre_h.jl: $(PCRE_INCL_PATH)
$(BUILDDIR)/errno_h.jl:
@$(call PRINT_PERL, echo '#include <errno.h>' | $(CPP) -dM - | perl -nle 'print "const $$1 = Int32($$2)" if /^#define\s+(E\w+)\s+(\d+)\s*$$/' | LC_ALL=C sort > $@)

$(BUILDDIR)/fenv_constants.jl: $(SRCDIR)/../src/fenv_constants.h
@$(PRINT_PERL) $(CPP_STDOUT) -DJULIA $< | tail -n 8 | perl -ple 's/\sFE_UN\w+/ 0x10/g; s/\sFE_O\w+/ 0x08/g; s/\sFE_DI\w+/ 0x04/g; s/\sFE_INV\w+/ 0x01/g; s/\sFE_TON\w+/ 0x00/g; s/\sFE_UP\w+/ 0x800/g; s/\sFE_DO\w+/ 0x400/g; s/\sFE_TOW\w+/ 0xc00/g' > $@

$(BUILDDIR)/file_constants.jl: $(SRCDIR)/../src/file_constants.h
@$(call PRINT_PERL, $(CPP_STDOUT) -DJULIA $< | perl -nle 'print "$$1 0o$$2" if /^(\s*const\s+[A-z_]+\s+=)\s+(0[0-9]*)\s*$$/; print "$$1" if /^\s*(const\s+[A-z_]+\s+=\s+([1-9]|0x)[0-9A-z]*)\s*$$/' > $@)

Expand Down Expand Up @@ -106,7 +103,7 @@ clean:
rm -f $(BUILDDIR)/errno_h.jl
rm -f $(BUILDDIR)/build_h.jl
rm -f $(BUILDDIR)/build_h.jl.phony
rm -f $(BUILDDIR)/fenv_constants.jl
rm -f $(BUILDDIR)/fenv_constants.jl # To be removed
rm -f $(BUILDDIR)/uv_constants.jl
rm -f $(BUILDDIR)/file_constants.jl
rm -f $(BUILDDIR)/version_git.jl
Expand Down
15 changes: 14 additions & 1 deletion base/rounding.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

module Rounding
include(String(vcat(length(Core.ARGS)>=2?Core.ARGS[2].data:"".data, "fenv_constants.jl".data))) # include($BUILDROOT/base/fenv_constants.jl)

let fenv_consts = Vector{Cint}(9)
ccall(:jl_get_fenv_consts, Void, (Ptr{Cint},), fenv_consts)
global const JL_FE_INEXACT = fenv_consts[1]
global const JL_FE_UNDERFLOW = fenv_consts[2]
global const JL_FE_OVERFLOW = fenv_consts[3]
global const JL_FE_DIVBYZERO = fenv_consts[4]
global const JL_FE_INVALID = fenv_consts[5]

global const JL_FE_TONEAREST = fenv_consts[6]
global const JL_FE_UPWARD = fenv_consts[7]
global const JL_FE_DOWNWARD = fenv_consts[8]
global const JL_FE_TOWARDZERO = fenv_consts[9]
end

export
RoundingMode, RoundNearest, RoundToZero, RoundUp, RoundDown, RoundFromZero,
Expand Down
12 changes: 0 additions & 12 deletions src/fenv_constants.h

This file was deleted.

16 changes: 16 additions & 0 deletions src/jlapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
#include "julia.h"

#ifdef __cplusplus
#include <cfenv>
extern "C" {
#else
#include <fenv.h>
#endif

#if defined(_OS_WINDOWS_) && !defined(_COMPILER_MINGW_)
Expand Down Expand Up @@ -367,6 +370,19 @@ JL_DLLEXPORT void (jl_cpu_wake)(void)
jl_cpu_wake();
}

JL_DLLEXPORT void jl_get_fenv_consts(int *ret)
{
ret[0] = FE_INEXACT;
ret[1] = FE_UNDERFLOW;
ret[2] = FE_OVERFLOW;
ret[3] = FE_DIVBYZERO;
ret[4] = FE_INVALID;
ret[5] = FE_TONEAREST;
ret[6] = FE_UPWARD;
ret[7] = FE_DOWNWARD;
ret[8] = FE_TOWARDZERO;
}

#ifdef __cplusplus
}
#endif