rational: add operator int
This commit is contained in:
parent
7ccad71e6e
commit
4b253a57f7
@ -96,6 +96,14 @@ rational<T>::operator double (void) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
rational<T>::operator int (void) const
|
||||||
|
{
|
||||||
|
return static_cast<int> (n / d);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
template <typename T>
|
template <typename T>
|
||||||
rational<T>
|
rational<T>
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* Copyright 2014 Danny Robson <danny@nerdcruft.net>
|
* Copyright 2014-2015 Danny Robson <danny@nerdcruft.net>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __UTIL_RATIONAL_HPP
|
#ifndef __UTIL_RATIONAL_HPP
|
||||||
@ -35,6 +35,7 @@ namespace util {
|
|||||||
|
|
||||||
explicit operator float (void) const;
|
explicit operator float (void) const;
|
||||||
explicit operator double (void) const;
|
explicit operator double (void) const;
|
||||||
|
explicit operator int (void) const;
|
||||||
|
|
||||||
rational<T> reduced (void) const;
|
rational<T> reduced (void) const;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user