This is a Ruby tree! It shows every object from the Ruby Programming Language in a tree format.
# BigDecimal < Numeric (from ruby core) --- BigDecimal provides arbitrary-precision floating point decimal arithmetic. ## Introduction Ruby provides built-in support for arbitrary precision integer arithmetic. For example: 42**13 #=> 1265437718438866624512 BigDecimal provides similar support for very large or very accurate floating point numbers. Decimal arithmetic is also useful for general calculation, because it provides the correct answers people expect--whereas normal binary floating point arithmetic often introduces subtle errors because of the conversion between base 10 and base 2. For example, try: sum = 0 10_000.times do sum = sum + 0.0001 end print sum #=> 0.9999999999999062 and contrast with the output from: require 'bigdecimal' sum = BigDecimal("0") 10_000.times do sum = sum + BigDecimal("0.0001") end print sum #=> 0.1E1 Similarly: (BigDecimal("1.2") - BigDecimal("1.0")) == BigDecimal("0.2") #=> true (1.2 - 1.0) == 0.2 #=> false ## A Note About Precision For a calculation using a BigDecimal and another `value`, the precision of the result depends on the type of `value`: * If `value` is a Float, the precision is Float::DIG + 1. * If `value` is a Rational, the precision is larger than Float::DIG + 1. * If `value` is a BigDecimal, the precision is `value`'s precision in the internal representation, which is platform-dependent. * If `value` is other object, the precision is determined by the result of +BigDecimal(value)+. ## Special features of accurate decimal arithmetic Because BigDecimal is more accurate than normal binary floating point arithmetic, it requires some special values. ### Infinity BigDecimal sometimes needs to return infinity, for example if you divide a value by zero. BigDecimal("1.0") / BigDecimal("0.0") #=> Infinity BigDecimal("-1.0") / BigDecimal("0.0") #=> -Infinity You can represent infinite numbers to BigDecimal using the strings `'Infinity'`, `'+Infinity'` and `'-Infinity'` (case-sensitive) ### Not a Number When a computation results in an undefined value, the special value `NaN` (for 'not a number') is returned. Example: BigDecimal("0.0") / BigDecimal("0.0") #=> NaN You can also create undefined values. NaN is never considered to be the same as any other value, even NaN itself: n = BigDecimal('NaN') n == 0.0 #=> false n == n #=> false ### Positive and negative zero If a computation results in a value which is too small to be represented as a BigDecimal within the currently specified limits of precision, zero must be returned. If the value which is too small to be represented is negative, a BigDecimal value of negative zero is returned. BigDecimal("1.0") / BigDecimal("-Infinity") #=> -0.0 If the value is positive, a value of positive zero is returned. BigDecimal("1.0") / BigDecimal("Infinity") #=> 0.0 (See BigDecimal.mode for how to specify limits of precision.) Note that `-0.0` and `0.0` are considered to be the same for the purposes of comparison. Note also that in mathematics, there is no particular concept of negative or positive zero; true mathematical zero has no sign. ## bigdecimal/util When you require `bigdecimal/util`, the #to_d method will be available on BigDecimal and the native Integer, Float, Rational, and String classes: require 'bigdecimal/util' 42.to_d # => 0.42e2 0.5.to_d # => 0.5e0 (2/3r).to_d(3) # => 0.667e0 "0.5".to_d # => 0.5e0 ## License Copyright (C) 2002 by Shigeo Kobayashi <shigeo@tinyforest.gr.jp>. BigDecimal is released under the Ruby and 2-clause BSD licenses. See LICENSE.txt for details. Maintained by mrkn <mrkn@mrkn.jp> and ruby-core members. Documented by zzak <zachary@zacharyscott.net>, mathew <meta@pobox.com>, and many other contributors. --- # Constants: BASE : Base value used in internal calculations. On a 32 bit system, BASE is 10000, indicating that calculation is done in groups of 4 digits. (If it were larger, BASE**2 wouldn't fit in 32 bits, so you couldn't guarantee that two groups could always be multiplied together without overflow.) EXCEPTION_ALL : Determines whether overflow, underflow or zero divide result in an exception being thrown. See BigDecimal.mode. EXCEPTION_INFINITY : Determines what happens when the result of a computation is infinity. See BigDecimal.mode. EXCEPTION_NaN : Determines what happens when the result of a computation is not a number (NaN). See BigDecimal.mode. EXCEPTION_OVERFLOW : Determines what happens when the result of a computation is an overflow (a result too large to be represented). See BigDecimal.mode. EXCEPTION_UNDERFLOW : Determines what happens when the result of a computation is an underflow (a result too small to be represented). See BigDecimal.mode. EXCEPTION_ZERODIVIDE : Determines what happens when a division by zero is performed. See BigDecimal.mode. INFINITY : Special value constants NAN : [not documented] ROUND_CEILING : Round towards +Infinity. See BigDecimal.mode. ROUND_DOWN : Indicates that values should be rounded towards zero. See BigDecimal.mode. ROUND_FLOOR : Round towards -Infinity. See BigDecimal.mode. ROUND_HALF_DOWN : Indicates that digits >= 6 should be rounded up, others rounded down. See BigDecimal.mode. ROUND_HALF_EVEN : Round towards the even neighbor. See BigDecimal.mode. ROUND_HALF_UP : Indicates that digits >= 5 should be rounded up, others rounded down. See BigDecimal.mode. ROUND_MODE : Determines what happens when a result must be rounded in order to fit in the appropriate number of significant digits. See BigDecimal.mode. ROUND_UP : Indicates that values should be rounded away from zero. See BigDecimal.mode. SIGN_NEGATIVE_FINITE : Indicates that a value is negative and finite. See BigDecimal.sign. SIGN_NEGATIVE_INFINITE : Indicates that a value is negative and infinite. See BigDecimal.sign. SIGN_NEGATIVE_ZERO : Indicates that a value is -0. See BigDecimal.sign. SIGN_NaN : Indicates that a value is not a number. See BigDecimal.sign. SIGN_POSITIVE_FINITE : Indicates that a value is positive and finite. See BigDecimal.sign. SIGN_POSITIVE_INFINITE : Indicates that a value is positive and infinite. See BigDecimal.sign. SIGN_POSITIVE_ZERO : Indicates that a value is +0. See BigDecimal.sign. VERSION : The version of bigdecimal library # Class methods: _load double_fig interpret_loosely json_create limit mode save_exception_mode save_limit save_rounding_mode # Instance methods: % * ** + +@ - -@ / < <= <=> == === > >= _dump abs add as_json ceil clone coerce div divmod dup eql? exponent finite? fix floor frac hash infinite? inspect modulo mult n_significant_digits nan? nonzero? power precision precision_scale precs quo remainder round scale sign split sqrt sub to_d to_digits to_f to_i to_int to_json to_r to_s truncate zero?
This is MURDOC! A Ruby documentation browser inspired by Smalltalk-80. It allows you to learn about Ruby by browsing through its class hierarchies, and see any of its methods.