Another question, Python modulo on floats, describes why Python's modulo has trouble with floats (I also understand that computer numbers are not numbers as covered in this essay, especially multiples of 3). However, I am having a similar, but different problem with modulo and the accepted answer does not work.
Here is a reproducible example in Python 3.7.1 on a MacBook Pro:
import numpy as np
x = np.array([2.012, 2.012 *2, 2.012 *3, 2.012 *4, 2.012 *5, 2.012 *6])
x % 2.012
# array([0.0000000e+00, 0.0000000e+00, 2.0120000e+00, 0.0000000e+00,
# 4.4408921e-16, 2.0120000e+00])
If I try the accepted answer, I still get the same problem:
from decimal import Decimal
Decimal(3*2.012) % Decimal(2.012)
# Decimal('2.011999999999999566568931186')
My specific question: How do I calculate the modulo and get zero for series such as my example?
Edited based upon feedback:
As a specific example, how do I do the modulo operator if my data looks like this (the specific values will be read in from actual data):
## X is read in from real data
x = np.array([2.012, 4.024, 6.036, 8.048, 1, 2, 3, 1.2, 1.3, 1.4, 1, 5, 6, 2.012, 2.012, 2.012])
[D(x) % D(frequency) for x in detections]
#[Decimal('0E-51'), Decimal('0E-51'), Decimal('2.011999999999999566568931186'), Decimal('0E-51'), Decimal('1.000000000000000000000000000'), Decimal('2.000000000000000000000000000'), Decimal('0.9879999999999999893418589636'), Decimal('1.199999999999999955591079015'), Decimal('1.300000000000000044408920985'), Decimal('1.399999999999999911182158030'), Decimal('1.000000000000000000000000000'), Decimal('0.9759999999999999786837179272'), Decimal('1.975999999999999978683717927'), Decimal('0E-51'), Decimal('0E-51'), Decimal('0E-51')]