Skip to content

Commit 14d2ac7

Browse files
committed
More robust fenv_constants
The constant is platform dependent and the macro definition may not expand to the value itself.
1 parent 03c2464 commit 14d2ac7

File tree

5 files changed

+33
-19
lines changed

5 files changed

+33
-19
lines changed

base/.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/pcre_h.jl
22
/errno_h.jl
33
/build_h.jl
4-
/fenv_constants.jl
54
/file_constants.jl
65
/uv_constants.jl
76
/version_git.jl

base/Makefile

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ else
1212
CPP_STDOUT := $(CPP) -E
1313
endif
1414

15-
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)
15+
all: $(addprefix $(BUILDDIR)/,pcre_h.jl errno_h.jl build_h.jl.phony file_constants.jl uv_constants.jl version_git.jl.phony)
1616

1717
PCRE_CONST := 0x[0-9a-fA-F]+|[0-9]+
1818
ifeq ($(USE_SYSTEM_PCRE), 1)
@@ -27,9 +27,6 @@ $(BUILDDIR)/pcre_h.jl: $(PCRE_INCL_PATH)
2727
$(BUILDDIR)/errno_h.jl:
2828
@$(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 > $@)
2929

30-
$(BUILDDIR)/fenv_constants.jl: $(SRCDIR)/../src/fenv_constants.h
31-
@$(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' > $@
32-
3330
$(BUILDDIR)/file_constants.jl: $(SRCDIR)/../src/file_constants.h
3431
@$(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*$$/' > $@)
3532

@@ -106,7 +103,7 @@ clean:
106103
rm -f $(BUILDDIR)/errno_h.jl
107104
rm -f $(BUILDDIR)/build_h.jl
108105
rm -f $(BUILDDIR)/build_h.jl.phony
109-
rm -f $(BUILDDIR)/fenv_constants.jl
106+
rm -f $(BUILDDIR)/fenv_constants.jl # To be removed
110107
rm -f $(BUILDDIR)/uv_constants.jl
111108
rm -f $(BUILDDIR)/file_constants.jl
112109
rm -f $(BUILDDIR)/version_git.jl

base/rounding.jl

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
# This file is a part of Julia. License is MIT: http://julialang.org/license
22

33
module Rounding
4-
include(String(vcat(length(Core.ARGS)>=2?Core.ARGS[2].data:"".data, "fenv_constants.jl".data))) # include($BUILDROOT/base/fenv_constants.jl)
4+
5+
# Use of `Cint` here makes MSVC unhappy
6+
let fenv_consts = Vector{Int32}(9)
7+
ccall(:jl_get_fenv_consts, Void, (Ptr{Int32},), fenv_consts)
8+
global const JL_FE_INEXACT = fenv_consts[1]
9+
global const JL_FE_UNDERFLOW = fenv_consts[2]
10+
global const JL_FE_OVERFLOW = fenv_consts[3]
11+
global const JL_FE_DIVBYZERO = fenv_consts[4]
12+
global const JL_FE_INVALID = fenv_consts[5]
13+
14+
global const JL_FE_TONEAREST = fenv_consts[6]
15+
global const JL_FE_UPWARD = fenv_consts[7]
16+
global const JL_FE_DOWNWARD = fenv_consts[8]
17+
global const JL_FE_TOWARDZERO = fenv_consts[9]
18+
end
519

620
export
721
RoundingMode, RoundNearest, RoundToZero, RoundUp, RoundDown, RoundFromZero,

src/fenv_constants.h

-12
This file was deleted.

src/jlapi.c

+16
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
#include "julia.h"
1515

1616
#ifdef __cplusplus
17+
#include <cfenv>
1718
extern "C" {
19+
#else
20+
#include <fenv.h>
1821
#endif
1922

2023
#if defined(_OS_WINDOWS_) && !defined(_COMPILER_MINGW_)
@@ -367,6 +370,19 @@ JL_DLLEXPORT void (jl_cpu_wake)(void)
367370
jl_cpu_wake();
368371
}
369372

373+
JL_DLLEXPORT void jl_get_fenv_consts(int *ret)
374+
{
375+
ret[0] = FE_INEXACT;
376+
ret[1] = FE_UNDERFLOW;
377+
ret[2] = FE_OVERFLOW;
378+
ret[3] = FE_DIVBYZERO;
379+
ret[4] = FE_INVALID;
380+
ret[5] = FE_TONEAREST;
381+
ret[6] = FE_UPWARD;
382+
ret[7] = FE_DOWNWARD;
383+
ret[8] = FE_TOWARDZERO;
384+
}
385+
370386
#ifdef __cplusplus
371387
}
372388
#endif

0 commit comments

Comments
 (0)