Decimal exponent, truncated rounding and symmetric rounding
DefinitionMetodosNumericos_errosDefsThe decimal exponent of a nonzero real, characterized by , together with truncated rounding and symmetric rounding of to digits of the normalized mantissa.
import Mathlib namespace MetodosNumericos /-- The decimal exponent of a nonzero real number: the integer `e` for which `0.1 ≤ |x| / 10 ^ e < 1`, i.e. the exponent of the normalized decimal form `x = f × 10 ^ e` with `0.1 ≤ |f| < 1`. -/ noncomputable def decExp (x : ℝ) : ℤ := ⌊Real.logb 10 |x|⌋ + 1 /-- Truncated rounding (arredondamento truncado) of `x` to `t` decimal digits of the normalized mantissa: the digits after the `t`-th are discarded. -/ noncomputable def truncRound (t : ℕ) (x : ℝ) : ℝ := (⌊x * (10 : ℝ) ^ ((t : ℤ) - decExp x)⌋ : ℝ) * (10 : ℝ) ^ (decExp x - (t : ℤ)) /-- Symmetric rounding (arredondamento simétrico) of `x` to `t` decimal digits of the normalized mantissa: the mantissa is rounded to the nearest multiple of `10 ^ (e - t)`, half being rounded away from the truncated value. -/ noncomputable def symRound (t : ℕ) (x : ℝ) : ℝ := (⌊x * (10 : ℝ) ^ ((t : ℤ) - decExp x) + 1 / 2⌋ : ℝ) * (10 : ℝ) ^ (decExp x - (t : ℤ)) end MetodosNumericos
Read-back
What the Lean code literally says, in plain math · self-authored-by-drafting-agent (non-blind)
Disclosure: this read-back is not blind. It was written by the same agent that drafted the Lean code, at the explicit instruction of the mission's human owner, and not by an independent auditor with fresh context.
Three real-valued definitions are given.
The first sends a real to the integer . It is total: for the logarithm of is taken to be by the library convention, so the value is .
The second takes a natural number and a real and returns
where the exponents are integers and denotes the integer power of in the reals. The floor is the greatest integer not exceeding its argument, so for negative the rounding is downwards rather than towards zero.
The third takes and and returns
with the same ; that is, the scaled value is rounded to the nearest integer with halves rounded upwards.
No hypothesis on the sign of or the size of is part of the definitions.