DCL 3.7.4
Loading...
Searching...
No Matches
Single Class Reference

#include <Numeric.h>

Public Member Functions

 Single (float _f)
String toString () const

Static Public Member Functions

static String toString (float _f, const wchar_t *_format)
static float parse (const wchar_t *_number) __DCL_THROWS1(NumericConvertException *)
static float parse (const wchar_t *_number, float _default)
static ByteString toByteString (float _f, const char *_format)

Public Attributes

float __f

Detailed Description

Definition at line 165 of file Numeric.h.

Constructor & Destructor Documentation

◆ Single()

Single::Single ( float _f)
inline

Definition at line 136 of file Numeric.inl.

137{
138 __f = _f;
139}
float __f
Definition Numeric.h:168

Member Function Documentation

◆ parse() [1/2]

float Single::parse ( const wchar_t * _number)
static

Definition at line 740 of file Numeric.cpp.

742{
743 __DCL_ASSERT(_number != NULL);
744
745 if (*_number == __T('\0') || iswspace((wint_t)*_number)) {
746 throw new NumericConvertException(_number, 0, 0);
747 }
748
749 NumericConvertException::Error error = NumericConvertException::NoError;
750 errno = 0;
751 wchar_t* endptr = NULL;
752 float n = wcstof(_number, &endptr);
753 if (errno == ERANGE) {
754 if (+HUGE_VALF == n || -HUGE_VALF == n) {
755 error = NumericConvertException::Overflow;
756 }
757 else if (!(FLT_MIN < n)) {
758 error = NumericConvertException::Underflow;
759 }
760 }
761
762 if (NumericConvertException::NoError != error) {
763 throw new NumericConvertException(
764 error,
765 _number,
766 0
767 );
768 }
769
770 if ((endptr && *endptr != '\0') || errno == EINVAL) {
771 throw new NumericConvertException(
772 _number,
773 0,
774 endptr ? (endptr - _number) : 0
775 );
776 }
777
778 return (float) n;
779}
#define NULL
Definition Config.h:312
#define __DCL_ASSERT(expr)
Definition Object.h:394
#define __T(str)
Definition Object.h:60

◆ parse() [2/2]

float Single::parse ( const wchar_t * _number,
float _default )
static

Definition at line 781 of file Numeric.cpp.

782{
783 __DCL_ASSERT(_number != NULL);
784
785 if (*_number == __T('\0') || iswspace((wint_t)*_number)) {
786 return _default;
787 }
788
789 NumericConvertException::Error error = NumericConvertException::NoError;
790 errno = 0;
791 wchar_t* endptr = NULL;
792 float n = wcstof(_number, &endptr);
793 if (errno == ERANGE) {
794 if (+HUGE_VALF == n || -HUGE_VALF == n) {
795 error = NumericConvertException::Overflow;
796 }
797 else if (!(FLT_MIN < n)) {
798 error = NumericConvertException::Underflow;
799 }
800 }
801
802 if (NumericConvertException::NoError != error) {
803 return _default;
804 }
805
806 if ((endptr && *endptr != '\0') || errno == EINVAL) {
807 return _default;
808 }
809
810 return (float) n;
811}

◆ toByteString()

ByteString Single::toByteString ( float _f,
const char * _format )
static

Definition at line 813 of file Numeric.cpp.

814{
815 if (!_format)
816 _format = "%.8g";
817
818 __DCL_ASSERT(*_format != '\0');
819
820 return ByteString::format(_format, _f);
821}

◆ toString() [1/2]

String Single::toString ( ) const
inline

Definition at line 141 of file Numeric.inl.

142{
143 return Single::toString(__f, NULL);
144}
String toString() const
Definition Numeric.inl:141

◆ toString() [2/2]

String Single::toString ( float _f,
const wchar_t * _format )
static

Definition at line 730 of file Numeric.cpp.

731{
732 if (!_format)
733 _format = __T("%.8g");
734
735 __DCL_ASSERT(*_format != '\0');
736
737 return String::format(_format, _f);
738}

Member Data Documentation

◆ __f

float Single::__f

Definition at line 168 of file Numeric.h.


The documentation for this class was generated from the following files: