⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fpenvironment.h

📁 This software aims to create an applet and panel tools to manage a wireless interface card, such as
💻 H
字号:
//
// FPEnvironment.h
//
// $Id: //poco/Main/Foundation/include/Foundation/FPEnvironment.h#5 $
//
// Definitions of class FPEnvironment.
//
// Copyright (c) 2004, Guenter Obiltschnig/Applied Informatics.
// All rights reserved.
// 
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 
// 1. Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
// 
// 2. Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
// 
// 3. Redistributions in any form must be accompanied by information on
//    how to obtain complete source code for this software and any
//    accompanying software that uses this software.  The source code
//    must either be included in the distribution or be available for no
//    more than the cost of distribution plus a nominal fee, and must be
//    freely redistributable under reasonable conditions.  For an
//    executable file, complete source code means the source code for all
//    modules it contains.  It does not include source code for modules or
//    files that typically accompany the major components of the operating
//    system on which the executable file runs.
// 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//


#ifndef Foundation_FPEnvironment_INCLUDED
#define Foundation_FPEnvironment_INCLUDED


#ifndef Foundation_Foundation_INCLUDED
#include "Foundation/Foundation.h"
#endif


#if defined(__osf__) || defined(__VMS)
#include "Foundation/FPEnvironment_DEC.h"
#elif defined(sun) || defined(__sun)
#include "Foundation/FPEnvironment_SUN.h"
#elif defined(POCO_OS_FAMILY_UNIX)
#include "Foundation/FPEnvironment_C99.h"
#elif defined(POCO_OS_FAMILY_WINDOWS)
#include "Foundation/FPEnvironment_WIN32.h"
#endif


Foundation_BEGIN


class Foundation_API FPEnvironment: private FPEnvironmentImp
	/// Instances of this class can be used to save
	/// and later restore the current floating
	/// point environment (consisting of rounding
	/// mode and floating-point flags).
	/// The class also provides various static
	/// methods to query certain properties
	/// of a floating-point number. 
{
public:
	enum RoundingMode
	{
		FP_ROUND_DOWNWARD   = FP_ROUND_DOWNWARD_IMP,
		FP_ROUND_UPWARD     = FP_ROUND_UPWARD_IMP,
		FP_ROUND_TONEAREST  = FP_ROUND_TONEAREST_IMP,
		FP_ROUND_TOWARDZERO = FP_ROUND_TOWARDZERO_IMP
	};

	enum Flag
	{
		FP_DIVIDE_BY_ZERO = FP_DIVIDE_BY_ZERO_IMP,
		FP_INEXACT        = FP_INEXACT_IMP,
		FP_OVERFLOW       = FP_OVERFLOW_IMP,
		FP_UNDERFLOW      = FP_UNDERFLOW_IMP,
		FP_INVALID        = FP_INVALID_IMP
	};

	FPEnvironment();
		/// Standard constructor.
		/// Remembers the current environment.

	FPEnvironment(RoundingMode mode);
		/// Remembers the current environment and
		/// sets the given rounding mode.
		
	FPEnvironment(const FPEnvironment& env);
		/// Copy constructor.
		
	~FPEnvironment();
		/// Restores the previous environment (unless
		/// keepCurrent() has been called previously)
		
	FPEnvironment& operator = (const FPEnvironment& env);
		/// Assignment operator

	void keepCurrent();
		/// Keep the current environment even after
		/// destroying the FPEnvironment object.

	static void clearFlags();
		/// Resets all flags.

	static bool isFlag(Flag flag);
		/// Returns true iff the given flag is set.
		
	static void setRoundingMode(RoundingMode mode);
		/// Sets the rounding mode.
		
	static RoundingMode getRoundingMode();
		/// Returns the current rounding mode.
		
	static bool isInfinite(float value);		
	static bool isInfinite(double value);
	static bool isInfinite(long double value);
		/// Returns true iff the given number is infinite.

	static bool isNaN(float value);		
	static bool isNaN(double value);
	static bool isNaN(long double value);
		/// Returns true iff the given number is NaN.

	static float copySign(float target, float source);		
	static double copySign(double target, double source);
	static long double copySign(long double target, long double source);
		/// Copies the sign from source to target.
};


//
// For convenience, we provide a shorter name for
// the FPEnvironment class.
//
typedef FPEnvironment FPE;


//
// inline's
//
inline bool FPEnvironment::isFlag(Flag flag)
{
	return isFlagImp(FlagImp(flag));
}


inline void FPEnvironment::setRoundingMode(RoundingMode mode)
{
	setRoundingModeImp(RoundingModeImp(mode));
}

	
inline FPEnvironment::RoundingMode FPEnvironment::getRoundingMode()
{
	return RoundingMode(getRoundingModeImp());
}

	
inline bool FPEnvironment::isInfinite(float value)
{
	return isInfiniteImp(value);
}


inline bool FPEnvironment::isInfinite(double value)
{
	return isInfiniteImp(value);
}


inline bool FPEnvironment::isInfinite(long double value)
{
	return isInfiniteImp(value);
}


inline bool FPEnvironment::isNaN(float value)
{
	return isNaNImp(value);
}


inline bool FPEnvironment::isNaN(double value)
{
	return isNaNImp(value);
}


inline bool FPEnvironment::isNaN(long double value)
{
	return isNaNImp(value);
}


inline float FPEnvironment::copySign(float target, float source)
{
	return copySignImp(target, source);
}


inline double FPEnvironment::copySign(double target, double source)
{
	return copySignImp(target, source);
}


inline long double FPEnvironment::copySign(long double target, long double source)
{
	return copySignImp(target, source);
}


Foundation_END


#endif // Foundation_FPEnvironment_INCLUDED

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -