symport/e32/euser/maths/um_spec.cpp
changeset 1 0a7b44b10206
child 2 806186ab5e14
equal deleted inserted replaced
0:c55016431358 1:0a7b44b10206
       
     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 "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-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 
       
    21 #include "um_std.h"
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 #ifndef __REALS_MACHINE_CODED__
       
    27 EXPORT_C TBool Math::IsZero(const TReal &aVal)
       
    28 /**
       
    29 Determines whether a value is zero.
       
    30 
       
    31 @param aVal A reference to the value to be checked.
       
    32 
       
    33 @return True, if aVal is zero; false, otherwise.
       
    34 */
       
    35 	{
       
    36 
       
    37 	SReal64 *pS=(SReal64 *)&aVal;
       
    38 
       
    39 	if (pS->msm==0U && pS->lsm==0U && pS->exp==(unsigned)KTReal64ZeroExponent)
       
    40 		return TRUE;
       
    41 	else
       
    42 		return FALSE;
       
    43 	}
       
    44 
       
    45 
       
    46 
       
    47 
       
    48 EXPORT_C TBool Math::IsNaN(const TReal &aVal)
       
    49 /**
       
    50 Determines whether a value is not a number.
       
    51 
       
    52 @param aVal A reference to the value to be checked.
       
    53 
       
    54 @return True, if aVal is not a number; false, otherwise.
       
    55 */
       
    56 	{
       
    57 
       
    58 	SReal64 *pS=(SReal64 *)&aVal;
       
    59 
       
    60 	if (pS->exp==(unsigned)KTReal64SpecialExponent && (pS->msm|pS->lsm)!= 0U)
       
    61 		return TRUE;
       
    62 	else
       
    63 		return FALSE;
       
    64 	}
       
    65 
       
    66 
       
    67 
       
    68 
       
    69 EXPORT_C TBool Math::IsInfinite(const TReal &aVal)
       
    70 /**
       
    71 Determines whether a value is infinite.
       
    72 
       
    73 @param aVal A reference to the value to be checked.
       
    74 
       
    75 @return True, if aVal is infinite; false, otherwise.
       
    76 */
       
    77 	{
       
    78 
       
    79 	SReal64 *pS=(SReal64 *)&aVal;
       
    80 
       
    81 	if (pS->msm==0U && pS->lsm==0U && pS->exp==(unsigned)KTReal64SpecialExponent)
       
    82 		return TRUE;
       
    83 	else
       
    84 		return FALSE;
       
    85 	}
       
    86 
       
    87 
       
    88 
       
    89 
       
    90 EXPORT_C TBool Math::IsFinite(const TReal &aVal)
       
    91 /**
       
    92 Determines whether a value is finite.
       
    93 
       
    94 In this context, a value is finite if it is a valid number and
       
    95 is not infinite.
       
    96 
       
    97 @param aVal A reference to the value to be checked.
       
    98 
       
    99 @return True, if aVal is finite; false, otherwise.
       
   100 */
       
   101 	{
       
   102 
       
   103 	SReal64 *pS=(SReal64 *)&aVal;
       
   104 
       
   105 	if (pS->exp!=(unsigned)KTReal64SpecialExponent)
       
   106 		return TRUE;
       
   107 	else
       
   108 		return FALSE;
       
   109 	}
       
   110 
       
   111 
       
   112 
       
   113 
       
   114 EXPORT_C void Math::SetZero(TReal &aVal,TInt aSign)
       
   115 //
       
   116 // Constructs zeros, assuming default sign is positive
       
   117 //
       
   118 	{
       
   119 
       
   120 	SReal64 *pS=(SReal64 *)&aVal;
       
   121 	pS->sign=aSign;
       
   122 	pS->exp=KTReal64ZeroExponent;
       
   123 	pS->msm=0;
       
   124 	pS->lsm=0;
       
   125 	}
       
   126 
       
   127 
       
   128 
       
   129 
       
   130 EXPORT_C void Math::SetNaN(TReal &aVal)
       
   131 //
       
   132 // Constructs NaN (+ve sign for Java)
       
   133 //
       
   134 	{
       
   135 
       
   136 	SReal64 *pS=(SReal64 *)&aVal;
       
   137 	pS->sign=0;
       
   138 	pS->exp=KTReal64SpecialExponent;
       
   139 	pS->msm=0xfffffu;
       
   140 	pS->lsm=0xffffffffu;
       
   141 	}
       
   142 
       
   143 
       
   144 
       
   145 
       
   146 EXPORT_C void Math::SetInfinite(TReal &aVal,TInt aSign)
       
   147 //
       
   148 // Constructs infinities
       
   149 //
       
   150 	{
       
   151 
       
   152 	SReal64 *pS=(SReal64 *)&aVal;
       
   153 	pS->sign=aSign;
       
   154 	pS->exp=KTReal64SpecialExponent;
       
   155 	pS->msm=0;
       
   156 	pS->lsm=0;
       
   157 	}
       
   158 #endif
       
   159