A Small Argument and a Directed Mode
Each of these functions comes to a simple value as its argument goes to nought: the sine to the argument itself, the cosine to one, the cosecant to one over the argument. Every one of those is a value the destination holds exactly, and that is awkward for a function that decides its rounding rather than assuming it. Deciding means evaluating wider than asked until every value the error allows rounds the same way, and an answer that lands on a value the destination holds has values on both sides of it that round differently, however wide the evaluation goes.
The three nearest modes do not notice, since the answer is that value either way. The four directed modes do, because they have to say which side of it the truth lies on.
from decimo import Decimal, RoundingMode
var tiny = Decimal("1E-500")
print(tiny.sin(precision=20, rounding_mode=RoundingMode.ROUND_DOWN))
# 9.9999999999999999999E-501 -- the sine is below its argument
print(tiny.tan(precision=20, rounding_mode=RoundingMode.ROUND_DOWN))
# 1.0000000000000000000E-500 -- the tangent is above it
print(tiny.cos(precision=20, rounding_mode=RoundingMode.ROUND_DOWN))
# 0.99999999999999999999 -- the cosine is below one
So such an argument is answered from the sign of the function’s own first
correction term, which is all the rounding needs: sin(x) = x - x^3/6 is
below x and tan(x) = x + x^3/3 is above it, and neither correction can be
computed at 1E-500 by any width a loop would reach.
A small argument is not the only place this happens. Wherever a function’s
value is a whole number, an argument a hair away from that point has an
answer a hair away from a value the destination holds, and the same thing
goes wrong. log10(1000) is three exactly; log10 of a thousand plus
1E-500 is three plus a correction five hundred digits down.
from decimo import Decimal, RoundingMode
var beside = Decimal("1000").add(Decimal("1E-500"))
print(beside.log10(precision=20, rounding_mode=RoundingMode.ROUND_UP))
# 3.0000000000000000001 -- above three, because the argument is above a thousand
print(beside.log10(precision=20, rounding_mode=RoundingMode.ROUND_DOWN))
# 3.0000000000000000000 -- and the same value truncated is three
BigFloat has the same answers for ln beside one, log2 and log10
beside a power of their base, and exp2 and exp10 beside a whole
argument.