rational: add operator int

This commit is contained in:
Danny Robson 2015-09-21 16:35:31 +10:00
parent 7ccad71e6e
commit 4b253a57f7
2 changed files with 10 additions and 1 deletions

View File

@ -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>
rational<T>

View File

@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2014 Danny Robson <danny@nerdcruft.net>
* Copyright 2014-2015 Danny Robson <danny@nerdcruft.net>
*/
#ifndef __UTIL_RATIONAL_HPP
@ -35,6 +35,7 @@ namespace util {
explicit operator float (void) const;
explicit operator double (void) const;
explicit operator int (void) const;
rational<T> reduced (void) const;