aboutsummaryrefslogblamecommitdiffstats
path: root/lib/orber/doc/src/fixed.xml
blob: 7c59071b49812e98f1cc8c7036b81c1b61e9102f (plain) (tree)































































































































































                                                                                                                     
<?xml version="1.0" encoding="latin1" ?>
<!DOCTYPE erlref SYSTEM "erlref.dtd">

<erlref>
  <header>
    <copyright>
      <year>2002</year>
      <year>2007</year>
      <holder>Ericsson AB, All Rights Reserved</holder>
    </copyright>
    <legalnotice>
  The contents of this file are subject to the Erlang Public License,
  Version 1.1, (the "License"); you may not use this file except in
  compliance with the License. You should have received a copy of the
  Erlang Public License along with this software. If not, it can be
  retrieved online at http://www.erlang.org/.

  Software distributed under the License is distributed on an "AS IS"
  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  the License for the specific language governing rights and limitations
  under the License.

  The Initial Developer of the Original Code is Ericsson AB.
    </legalnotice>

    <title>fixed</title>
    <prepared></prepared>
    <responsible></responsible>
    <docno></docno>
    <approved></approved>
    <checked></checked>
    <date>2002-05-22</date>
    <rev>A</rev>
  </header>
  <module>fixed</module>
  <modulesummary>the corba fixed type</modulesummary>
  <description>
    <p>This module contains functions that gives an interface to the CORBA fixed type.</p>
    <p>The type <c>Fixed</c> used below is defined as:</p>
    <code type="none">
      -record(fixed, {digits, scale, value}).
    </code>
    <p>where <c>digits</c> is the total amount of digits it consists of and 
      <c>scale</c> is the number of fractional digits. The <c>value</c> field
      contains the actual Fixed value represented as an integer. The limitations
      of each field are:</p>
    <list type="bulleted">
      <item>Digits - integer(), -1 > Digits &lt; 32</item>
      <item>Scale - integer(), -1 > Scale =&lt; Digits</item>
      <item>Value - integer(), range (31 digits): &plusmn;9999999999999999999999999999999</item>
    </list>
    <p>Since the Value part is represented by an integer, it is vital that the
      Digits and Scale values are correct. This also means that trailing zeros
      cannot be left out in some cases:</p>
    <list type="bulleted">
      <item>fixed&lt;5,3> eq. 03.140d eq. 3140</item>
      <item>fixed&lt;3,2> eq. 3.14d eq. 314</item>
    </list>
    <p>Leading zeros can be left out.</p>
    <p>For your convenience, this module exports functions which handle
      unary (<c>-</c>) and binary (<c>+-*/</c>) operations legal for the Fixed type.
      Since a unary <c>+</c> have no effect, this module do not export such a 
      function. Any of the binary operations may cause an overflow (i.e. more than
      31 significant digits; leading and trailing zeros are not considered 
      significant). If this is the case, the Digit and Scale values are adjusted
      and the Value truncated (no rounding performed). This behavior is
      compliant with the OMG CORBA specification. Each binary operation have
      the following upper bounds:</p>
    <list type="bulleted">
      <item><em>Fixed1 + Fixed2</em> - <c><![CDATA[fixed<max(d1-s1,d2-s2) + max(s1,s2) + 1, max(s1,s2)>]]></c></item>
      <item><em>Fixed1 - Fixed2</em> - <c><![CDATA[fixed<max(d1-s1,d2-s2) + max(s1,s2) + 1, max(s1,s2)>]]></c></item>
      <item><em>Fixed1 * Fixed2</em> - <c><![CDATA[fixed<d1+d2, s1+s2>]]></c></item>
      <item><em>Fixed1 / Fixed2</em> - <c><![CDATA[fixed<(d1-s1+s2) + Sinf ,Sinf >]]></c></item>
    </list>
    <p>A quotient may have an arbitrary number of decimal places, which is 
      denoted by a scale of Sinf.</p>
  </description>
  <funcs>
    <func>
      <name>create(Digits, Scale, Value) -> Result</name>
      <fsummary>Create a fixed type</fsummary>
      <type>
        <v>Result = Fixed Type | {'EXCEPTION', #'BAD_PARAM'{}}</v>
      </type>
      <desc>
        <p>This function creates a new instance of a <c>Fixed Type</c>. If
          the limitations is not fulfilled (e.g. overflow) an exception is
          raised.</p>
      </desc>
    </func>
    <func>
      <name>get_typecode(Fixed) -> Result</name>
      <fsummary>Create TypeCode representing the supplied fixed type</fsummary>
      <type>
        <v>Result = TypeCode | {'EXCEPTION', #'BAD_PARAM'{}}</v>
      </type>
      <desc>
        <p>Returns the TypeCode which represents the supplied Fixed type.
          If the parameter is not of the correct type, an exception is raised.</p>
      </desc>
    </func>
    <func>
      <name>add(Fixed1, Fixed2) -> Result</name>
      <fsummary>Add the supplied Fixed types</fsummary>
      <type>
        <v>Result = Fixed1 + Fixed2 | {'EXCEPTION', #'BAD_PARAM'{}}</v>
      </type>
      <desc>
        <p>Performs a Fixed type addition.
          If the parameters are not of the correct type, an exception is raised.</p>
      </desc>
    </func>
    <func>
      <name>subtract(Fixed1, Fixed2) -> Result</name>
      <fsummary>Subtract Fixed2 from Fixed1</fsummary>
      <type>
        <v>Result = Fixed1 - Fixed2 | {'EXCEPTION', #'BAD_PARAM'{}}</v>
      </type>
      <desc>
        <p>Performs a Fixed type subtraction.
          If the parameters are not of the correct type, an exception is raised.</p>
      </desc>
    </func>
    <func>
      <name>multiply(Fixed1, Fixed2) -> Result</name>
      <fsummary>Multiply Fixed1 with Fixed2</fsummary>
      <type>
        <v>Result = Fixed1 * Fixed2 | {'EXCEPTION', #'BAD_PARAM'{}}</v>
      </type>
      <desc>
        <p>Performs a Fixed type multiplication.
          If the parameters are not of the correct type, an exception is raised.</p>
      </desc>
    </func>
    <func>
      <name>divide(Fixed1, Fixed2) -> Result</name>
      <fsummary>Divide Fixed1 with Fixed2</fsummary>
      <type>
        <v>Result = Fixed1 / Fixed2 | {'EXCEPTION', #'BAD_PARAM'{}}</v>
      </type>
      <desc>
        <p>Performs a Fixed type division.
          If the parameters are not of the correct type, an exception is raised.</p>
      </desc>
    </func>
    <func>
      <name>unary_minus(Fixed) -> Result</name>
      <fsummary>Negate the supplied Fixed Type</fsummary>
      <type>
        <v>Result = -Fixed | {'EXCEPTION', #'BAD_PARAM'{}}</v>
      </type>
      <desc>
        <p>Negates the supplied Fixed type.
          If the parameter is not of the correct type, an exception is raised.</p>
      </desc>
    </func>
  </funcs>
  
</erlref>