Source for file Float.class.php

Documentation is available at Float.class.php

  1. <?php
  2.  
  3. /**
  4. * @since 7/14/05
  5. * @package harmoni.primitives.numbers
  6. *
  7. * @copyright Copyright &copy; 2005, Middlebury College
  8. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  9. *
  10. * @version $Id: Float.class.php,v 1.6 2007/09/04 20:25:28 adamfranco Exp $
  11. */
  12.  
  13. require_once(dirname(__FILE__)."/Number.class.php");
  14.  
  15. /**
  16. * A simple Float data type.
  17. *
  18. * @package harmoni.primitives.numbers
  19. *
  20. * @copyright Copyright &copy; 2005, Middlebury College
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  22. *
  23. * @version $Id: Float.class.php,v 1.6 2007/09/04 20:25:28 adamfranco Exp $
  24. */
  25. class Float
  26. extends Number
  27. {
  28. /*******************************************************
  29. * Class Methods - Instance Creation
  30. *********************************************************/
  31.  
  32.  
  33. /**
  34. * Answer a new object with the value specified
  35. *
  36. * @param mixed $value
  37. * @param optional string $class The class to instantiate. Do NOT use outside
  38. * of this package.
  39. * @return object Float
  40. * @access public
  41. * @since 7/14/05
  42. */
  43. function withValue ( $value, $class = 'Float') {
  44. return parent::withValue($value, $class);
  45. }
  46.  
  47. /**
  48. * Answer a new object with the value specified
  49. *
  50. * @param string $string a string representation of the object
  51. * @return object Double
  52. * @access public
  53. * @since 3/14/06
  54. */
  55. function fromString ($string, $class = 'Float') {
  56. return parent::fromString($string, $class);
  57. }
  58.  
  59. /**
  60. * Answer a new object with the value zero
  61. *
  62. * @param optional string $class The class to instantiate. Do NOT use outside
  63. * of this package.
  64. * @return object Float
  65. * @access public
  66. * @since 7/14/05
  67. */
  68. function zero ( $class = 'Float') {
  69. return parent::zero($class);
  70. }
  71. /*******************************************************
  72. * Instance Methods - Arithmatic
  73. *********************************************************/
  74.  
  75. /**
  76. * Answer the sum of the receiver and aNumber.
  77. *
  78. * @param object Number $aNumber
  79. * @return object Number
  80. * @access public
  81. * @since 7/14/05
  82. */
  83. function plus ( $aNumber ) {
  84. $class = get_class($this);
  85. eval('$obj = '.$class.'::withValue($this->value() + $aNumber->value());');
  86. return $obj;
  87. }
  88. /**
  89. * Answer the result of multiplying the receiver and aNumber.
  90. *
  91. * @param object Number $aNumber
  92. * @return object Number
  93. * @access public
  94. * @since 7/14/05
  95. */
  96. function multipliedBy ( $aNumber ) {
  97. $class = get_class($this);
  98. eval('$obj = '.$class.'::withValue($this->value() * $aNumber->value());');
  99. return $obj;
  100. }
  101. /**
  102. * Answer the result of dividing the receiver and aNumber.
  103. *
  104. * @param object Number $aNumber
  105. * @return object Number
  106. * @access public
  107. * @since 7/14/05
  108. */
  109. function dividedBy ( $aNumber ) {
  110. $class = get_class($this);
  111. eval('$obj = '.$class.'::withValue($this->value() / $aNumber->value());');
  112. return $obj;
  113. }
  114. /*******************************************************
  115. * Instance Methods - Private
  116. *********************************************************/
  117.  
  118. /**
  119. * Set the internal value to a PHP primitive.
  120. *
  121. * @param mixed $value
  122. * @return void
  123. * @access private
  124. * @since 7/14/05
  125. */
  126. function _setValue ( $value ) {
  127. $this->_value = floatval($value);
  128. }
  129. }

Documentation generated on Wed, 19 Sep 2007 10:23:17 -0400 by phpDocumentor 1.3.0RC3