kernel/eka/euser/maths/um_spec.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32\euser\maths\um_spec.cpp
       
    15 // Functions to check for  and set special values
       
    16 // 
       
    17 //
       
    18 
       
    19 
       
    20 #include "um_std.h"
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 #ifndef __REALS_MACHINE_CODED__
       
    26 EXPORT_C TBool Math::IsZero(const TReal &aVal)
       
    27 /**
       
    28 Determines whether a value is zero.
       
    29 
       
    30 @param aVal A reference to the value to be checked. 
       
    31 
       
    32 @return True, if aVal is zero; false, otherwise.
       
    33 */
       
    34 	{
       
    35 
       
    36 	SReal64 *pS=(SReal64 *)&aVal;
       
    37 
       
    38 	if (pS->msm==0 && pS->lsm==0 && pS->exp==KTReal64ZeroExponent)
       
    39 		return TRUE;
       
    40 	else
       
    41 		return FALSE;
       
    42 	}
       
    43 
       
    44 
       
    45 
       
    46 
       
    47 EXPORT_C TBool Math::IsNaN(const TReal &aVal)
       
    48 /**
       
    49 Determines whether a value is not a number.
       
    50 
       
    51 @param aVal A reference to the value to be checked. 
       
    52 
       
    53 @return True, if aVal is not a number; false, otherwise.
       
    54 */
       
    55 	{
       
    56 
       
    57 	SReal64 *pS=(SReal64 *)&aVal;
       
    58 
       
    59 	if (pS->exp==KTReal64SpecialExponent && (pS->msm|pS->lsm)!=0)
       
    60 		return TRUE;
       
    61 	else
       
    62 		return FALSE;
       
    63 	}
       
    64 
       
    65 
       
    66 
       
    67 
       
    68 EXPORT_C TBool Math::IsInfinite(const TReal &aVal)
       
    69 /**
       
    70 Determines whether a value is infinite.
       
    71 
       
    72 @param aVal A reference to the value to be checked.
       
    73 
       
    74 @return True, if aVal is infinite; false, otherwise.
       
    75 */
       
    76 	{
       
    77 
       
    78 	SReal64 *pS=(SReal64 *)&aVal;
       
    79 	
       
    80 	if (pS->msm==0 && pS->lsm==0 && pS->exp==KTReal64SpecialExponent)
       
    81 		return TRUE;
       
    82 	else 
       
    83 		return FALSE;
       
    84 	}
       
    85 
       
    86 
       
    87 
       
    88 
       
    89 EXPORT_C TBool Math::IsFinite(const TReal &aVal)
       
    90 /**
       
    91 Determines whether a value is finite.
       
    92 
       
    93 In this context, a value is finite if it is a valid number and
       
    94 is not infinite.
       
    95 
       
    96 @param aVal A reference to the value to be checked.
       
    97 
       
    98 @return True, if aVal is finite; false, otherwise.
       
    99 */
       
   100 	{
       
   101 
       
   102 	SReal64 *pS=(SReal64 *)&aVal;
       
   103 	
       
   104 	if (pS->exp!=KTReal64SpecialExponent)
       
   105 		return TRUE;
       
   106 	else 
       
   107 		return FALSE;
       
   108 	}
       
   109 
       
   110 
       
   111 
       
   112 
       
   113 EXPORT_C void Math::SetZero(TReal &aVal,TInt aSign)
       
   114 //
       
   115 // Constructs zeros, assuming default sign is positive
       
   116 //
       
   117 	{
       
   118 
       
   119 	SReal64 *pS=(SReal64 *)&aVal;
       
   120 	pS->sign=aSign;
       
   121 	pS->exp=KTReal64ZeroExponent;
       
   122 	pS->msm=0;
       
   123 	pS->lsm=0;
       
   124 	}
       
   125 
       
   126 
       
   127 
       
   128 
       
   129 EXPORT_C void Math::SetNaN(TReal &aVal)
       
   130 //
       
   131 // Constructs NaN (+ve sign for Java)
       
   132 //
       
   133 	{
       
   134 
       
   135 	SReal64 *pS=(SReal64 *)&aVal;
       
   136 	pS->sign=0;
       
   137 	pS->exp=KTReal64SpecialExponent;
       
   138 	pS->msm=0xfffffu;
       
   139 	pS->lsm=0xffffffffu;
       
   140 	}
       
   141 
       
   142 
       
   143 
       
   144 
       
   145 EXPORT_C void Math::SetInfinite(TReal &aVal,TInt aSign)
       
   146 //
       
   147 // Constructs infinities
       
   148 //
       
   149 	{
       
   150 
       
   151 	SReal64 *pS=(SReal64 *)&aVal;
       
   152 	pS->sign=aSign;
       
   153 	pS->exp=KTReal64SpecialExponent;
       
   154 	pS->msm=0;
       
   155 	pS->lsm=0;
       
   156 	}
       
   157 #endif
       
   158