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

change float128 to longdouble to fix compilation using MS compiler #76

Merged
merged 2 commits into from
Oct 27, 2018
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
14 changes: 7 additions & 7 deletions cftime/_cftime.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ cdef int[12] _dpm_360 = [30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]
cdef int[13] _spm_365day = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365]
cdef int[13] _spm_366day = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366]

__version__ = '1.0.2'
__version__ = '1.0.2.1'

# Adapted from http://delete.me.uk/2005/03/iso8601.html
# Note: This regex ensures that all ISO8601 timezone formats are accepted - but, due to legacy support for other timestrings, not all incorrect formats can be rejected.
Expand Down Expand Up @@ -397,7 +397,7 @@ def JulianDayFromDate(date, calendar='standard'):
minute = year.copy()
second = year.copy()
microsecond = year.copy()
jd = np.empty(year.shape, np.float128)
jd = np.empty(year.shape, np.longdouble)
cdef long double[:] jd_view = jd
cdef Py_ssize_t i_max = len(date)
cdef Py_ssize_t i
Expand All @@ -422,7 +422,7 @@ def JulianDayFromDate(date, calendar='standard'):
# This is about 45 microseconds in 2000 for Julian date starting -4712.
# (pull request #433).
if calendar not in ['all_leap','no_leap','360_day','365_day','366_day']:
eps = np.array(np.finfo(np.float64).eps,np.float128)
eps = np.array(np.finfo(np.float64).eps,np.longdouble)
eps = np.maximum(eps*jd, eps)
jd += eps

Expand Down Expand Up @@ -453,13 +453,13 @@ def DateFromJulianDay(JD, calendar='standard', only_use_cftime_datetimes=False,
objects are used, which are actually instances of cftime.datetime.
"""

julian = np.array(JD, dtype=np.float128)
julian = np.array(JD, dtype=np.longdouble)

# get the day (Z) and the fraction of the day (F)
# use 'round half up' rounding instead of numpy's even rounding
# so that 0.5 is rounded to 1.0, not 0 (cftime issue #49)
Z = np.atleast_1d(np.int32(_round_half_up(julian)))
F = np.atleast_1d(julian + 0.5 - Z).astype(np.float128)
F = np.atleast_1d(julian + 0.5 - Z).astype(np.longdouble)

cdef Py_ssize_t i_max = len(Z)
year = np.empty(i_max, dtype=np.int32)
Expand All @@ -486,7 +486,7 @@ def DateFromJulianDay(JD, calendar='standard', only_use_cftime_datetimes=False,
microsecond = (second % 1)*1.e6
# remove the offset from the microsecond calculation.
if calendar not in ['all_leap','no_leap','360_day','365_day','366_day']:
eps = np.array(np.finfo(np.float64).eps,np.float128)
eps = np.array(np.finfo(np.float64).eps,np.longdouble)
eps = np.maximum(eps*julian, eps)
microsecond = np.clip(microsecond - eps*86400.*1e6, 0, 999999)

Expand Down Expand Up @@ -723,7 +723,7 @@ units to datetime objects.
if self.origin.year == 0:
msg='zero not allowed as a reference year, does not exist in Julian or Gregorian calendars'
raise ValueError(msg)
self.tzoffset = np.array(tzoffset,dtype=np.float128) # time zone offset in minutes
self.tzoffset = np.array(tzoffset,dtype=np.longdouble) # time zone offset in minutes
self.units = units
self.unit_string = unit_string
if self.calendar in ['noleap', '365_day'] and self.origin.month == 2 and self.origin.day == 29:
Expand Down
17 changes: 11 additions & 6 deletions test/test_cftime.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,13 @@ def runTest(self):
dateref = datetime(2015,2,28,12)
ntimes = 1001
verbose = True # print out max error diagnostics
precis = np.finfo(np.longdouble).precision
if precis < 18:
fact = 10
else:
fact = 1.
for calendar in calendars:
eps = 10.
eps = 10.*fact
units = 'microseconds since 2000-01-30 01:01:01'
microsecs1 = date2num(dateref,units,calendar=calendar)
maxerr = 0
Expand All @@ -355,7 +360,7 @@ def runTest(self):
print('calender = %s max abs err (microsecs) = %s eps = %s' % \
(calendar,maxerr,eps))
units = 'milliseconds since 1800-01-30 01:01:01'
eps = 0.01
eps = 0.01*fact
millisecs1 = date2num(dateref,units,calendar=calendar)
maxerr = 0.
for n in range(ntimes):
Expand All @@ -370,7 +375,7 @@ def runTest(self):
if verbose:
print('calender = %s max abs err (millisecs) = %s eps = %s' % \
(calendar,maxerr,eps))
eps = 1.e-4
eps = 1.e-4*fact
units = 'seconds since 0001-01-30 01:01:01'
secs1 = date2num(dateref,units,calendar=calendar)
maxerr = 0.
Expand All @@ -386,7 +391,7 @@ def runTest(self):
if verbose:
print('calender = %s max abs err (secs) = %s eps = %s' % \
(calendar,maxerr,eps))
eps = 1.e-6
eps = 1.e-6*fact
units = 'minutes since 0001-01-30 01:01:01'
mins1 = date2num(dateref,units,calendar=calendar)
maxerr = 0.
Expand All @@ -402,7 +407,7 @@ def runTest(self):
if verbose:
print('calender = %s max abs err (mins) = %s eps = %s' % \
(calendar,maxerr,eps))
eps = 1.e-7
eps = 1.e-7*fact
units = 'hours since 0001-01-30 01:01:01'
hrs1 = date2num(dateref,units,calendar=calendar)
maxerr = 0.
Expand All @@ -418,7 +423,7 @@ def runTest(self):
if verbose:
print('calender = %s max abs err (hours) = %s eps = %s' % \
(calendar,maxerr,eps))
eps = 1.e-9
eps = 1.e-9*fact
units = 'days since 0001-01-30 01:01:01'
days1 = date2num(dateref,units,calendar=calendar)
maxerr = 0.
Expand Down