Rounding

"Rounding strategy" - how to apply an AmountStyle's display precision to a posting amount (and its cost, if any). Mainly used to customise print's output, with --round=none|soft|hard|all.
Rounding rationals to significant digits and decimal places. The round function from the prelude returns an integer. The standard librarys of C and C++ have round functions that return floating point numbers. Rounding in this library takes and returns Rationals and can round to a number of significant digits or a number of decimal places.
This module provides various combinations of explicit floating point operations. The are three supported rounding variants:
  • ceil (rounding towards positive infinity)
  • floor (rounding towards negative infinity)
  • truncate (rounding towards zero)
Operators:
  • + add
  • - subtract
  • * multiplicate
  • / divide
  • sqrt squareRoot
  • id converting numbers between formats
The floating point data types: The behaviour for NaNs is very hardware dependent. In case an operation would result in a NaN the corresponding round-to-nearest-even-on-tie variant is used to get the result.
Not on Stackage, so not searched. Explicit floating point rounding mode wrappers
Rounding mode to be used for the IEEE floating-point operations. Note that Haskell's default is RoundNearestTiesToEven. If you use a different rounding mode, then the counter-examples you get may not match what you observe in Haskell.
Rounding modes for IEEE-754 floating point operations.
A RoundingAdvice is interpreted by divisions and rounding operations to specify the expected loss of precision and the rounding behaviour. RoundingAdvice is a pair of a RoundingMode and a target precision of type Maybe Natural. The precision defines the number of digits after the decimal point. If Nothing is given as precision all decimal digits are to be preserved, that is precision is not limited.
RoundingMode defines how to handle loss of precision in divisions or explicit rounding.
rounding variants floor, ceil and truncate for floating point operations +-*/√… There is an exact definition for +-*/√ over the real numbers in mathematics. However for performant, flexible and ergonomic numerical computations one ought to restrict oneself only having a finite subset of rational numbers. The most common data type for such use cases is the single and double floating point format. Combining two real floating point numbers by an operator yield a mathematical and exactly defined result. This exact result might not be representable as a floating point number. One has to round. The most common way of rounding is rounding to the nearest representable float. This rounding variant helps to minimize the accumulation of rounding errors over several floating point operations. Other rounding variants floor, ceil and truncate are useful for computing error bounds of chained floating point instructions. floor chooses the lesser neighbor of the representable results. ceil chooses the greater float. truncate chooses the float that is closest to zero. This library implements the floating point instructions in pure hasekell. They do not use `c++` with fegetround for example. That way they can be used in the WebAssembly backend of ghc since WebAssembly does neither support rounding variants nor fegetround. This module is supposed to expose the fastest possible clean interface of rounding variants. Should there ever be some compiler intrinsics for rounding variants then these shall be used in a future version. Internally the module heavily utilizes the Rational data type. First the operations result is calculated twice. One time exact with the help of Rational. Then there is also a round-to-nearest-even-on-tie result calculated. After that both numbers are compared to investigate if the round-to-nearest-even-on-tie result was rounded in the correct direction by chance. Should that not be the case the other neighbor is determined and returned. Every combination of number type (Float, Double) and operator (+,-,*,/,,id) is exported separately. The exported functions are supposed to be useful for interval arithmetic.
Rounding mode to use for floating-point conversions
One interesting aspect of floating-point is that the chosen rounding-mode can effect the results of a computation if the exact result cannot be precisely represented. SBV exports the functions fpAdd, fpSub, fpMul, fpDiv, fpFMA and fpSqrt which allows users to specify the IEEE supported RoundingMode for the operation. This example illustrates how SBV can be used to find rounding-modes where, for instance, addition can produce different results. We have:
>>> roundingAdd
Satisfiable. Model:
rm = RoundTowardPositive :: RoundingMode
x  =          -4.0039067 :: Float
y  =            131076.0 :: Float
(Note that depending on your version of Z3, you might get a different result.) Unfortunately Haskell floats do not allow computation with arbitrary rounding modes, but SBV's SFloatingPoint type does. We have:
>>> sat $ \x -> x .== (fpAdd sRoundTowardPositive (-4.0039067) 131076.0 :: SFloat)
Satisfiable. Model:
s0 = 131072.0 :: Float

>>> (-4.0039067) + 131076.0 :: Float
131071.99
We can see why these two results are indeed different: The 'RoundTowardPositive (which rounds towards positive infinity) produces a larger result.
>>> (-4.0039067) + 131076.0 :: Double
131071.9960933
we see that the "more precise" result is larger than what the Float value is, justifying the larger value with 'RoundTowardPositive. A more detailed study is beyond our current scope, so we'll merely note that floating point representation and semantics is indeed a thorny subject.
Asks the widget that the input context is attached to to delete characters around the cursor position by emitting the imContextDeleteSurrounding signal. In order to use this function, you should first call imContextGetSurrounding to get the current context, and call this function immediately afterwards to make sure that you know what you are deleting. You should also account for the fact that even if the signal was handled, the input context might not have deleted all the characters that were requested to be deleted. This function is used by an input method that wants to make substitutions in the existing text in response to new input. It is not useful for applications.
This signal is emitted when the input method needs to delete all or part of the context surrounding the cursor. Parameters: offset - the character offset from the cursor position of the text to be deleted. A negative value indicates a position before the cursor. n_chars - the number of characters to be deleted. Returns True if the signal was handled.
Retrieves context around the insertion point. Input methods typically want context in order to constrain input text based on existing text; this is important for languages such as Thai where only some sequences of characters are allowed. This function is implemented by emitting the imContextRetrieveSurrounding signal on the input method; in response to this signal, a widget should provide as much context as is available, up to an entire paragraph, by calling imContextSetSurrounding. Note that there is no obligation for a widget to respond to the imContextRetrieveSurrounding signal, so input methods must be prepared to function without context.
This signal is emitted when the input method requires the context surrounding the cursor. The callback should set the input method surrounding context by calling imContextSetSurrounding. Returns True if the signal was handled.
Sets surrounding context around the insertion point and preedit string. This function is expected to be called in response to the imContextRetrieveSurrounding signal, and will likely have no effect if called at other times.
Configure whether the table draws a border on its exterior.
The deleteSurrounding signal is emitted when the input method needs to delete all or part of the context surrounding the cursor.