Home » Developing U++ » U++ Developers corner » Value with type float
Re: Value with type float [message #58368 is a reply to message #58367] |
Tue, 10 May 2022 15:44   |
 |
mirek
Messages: 14256 Registered: November 2005
|
Ultimate Member |
|
|
Tom1 wrote on Tue, 10 May 2022 13:21Hi Mirek,
Sorry to return to this subject, but could you consider adding Null support for float?
I had something like this in mind... (in Core/Defs.h):
const int INT_NULL = INT_MIN;
const int64 INT64_NULL = INT64_MIN;
constexpr double DOUBLE_NULL = -std::numeric_limits<double>::infinity();
constexpr float FLOAT_NULL = -std::numeric_limits<float>::infinity();
class Nuller {
public:
operator int() const { return INT_NULL; }
operator int64() const { return INT64_NULL; }
operator double() const { return DOUBLE_NULL; }
operator float() const { return FLOAT_NULL; }
operator bool() const { return false; }
Nuller() {}
};
extern const Nuller Null;
template <class T> void SetNull(T& x) { x = Null; }
template <class T> bool IsNull(const T& x) { return x.IsNullInstance(); }
template<> inline bool IsNull(const int& i) { return i == INT_NULL; }
template<> inline bool IsNull(const int64& i) { return i == INT64_NULL; }
template<> inline bool IsNull(const double& r) { return !(std::abs(r) < std::numeric_limits<double>::infinity()); }
template<> inline bool IsNull(const float& r) { return !(std::abs(r) < std::numeric_limits<float>::infinity()); }
template<> inline bool IsNull(const bool& r ) { return false; }
Although, I'm not entirely sure, if this is completely correct way to do it.
Best regards,
Tom
PS. EDIT: I think the above should work mostly. Only the "Cout() << FLOAT_NULL;" prints -inf instead of empty field, which is the default for "Cout() << DOUBLE_NULL;":
CONSOLE_APP_MAIN{
double d=Null;
float f=Null;
double a=f;
float b=d;
Cout() << "d = " << d << "\n";
Cout() << "f = " << f << "\n";
Cout() << "a = " << a << "\n";
Cout() << "b = " << b << "\n";
Cout() << "a == f : " << (bool)(a==f) << "\n";
Cout() << "b == d : " << (bool)(b==d) << "\n";
Cout() << "IsNull(d) = " << IsNull(d) << "\n";
Cout() << "IsNull(f) = " << IsNull(f) << "\n";
Cout() << "IsNull(a) = " << IsNull(a) << "\n";
Cout() << "IsNull(b) = " << IsNull(b) << "\n";
}
IDK. Does it solve any real problem?
Up until this year, I have considered double-float relation to be similar to int-int16. You use float to reduce memory consumption or for special things (GPU), but you really do not need to support it in Value or widgets. Served me well for many many years. What has changed? 
Mirek
|
|
|
 |
|
Value with type float
|
 |
|
Re: Value with type float
By: mirek on Sat, 19 March 2022 10:38
|
 |
|
Re: Value with type float
|
 |
|
Re: Value with type float
By: Tom1 on Thu, 31 March 2022 13:49
|
 |
|
Re: Value with type float
By: Tom1 on Thu, 31 March 2022 15:14
|
 |
|
Re: Value with type float
By: mirek on Fri, 01 April 2022 11:07
|
 |
|
Re: Value with type float
By: Tom1 on Fri, 01 April 2022 11:13
|
 |
|
Re: Value with type float
By: Tom1 on Fri, 01 April 2022 12:06
|
 |
|
Re: Value with type float
By: Tom1 on Fri, 01 April 2022 14:03
|
 |
|
Re: Value with type float
By: Tom1 on Fri, 01 April 2022 15:26
|
 |
|
Re: Value with type float
By: mirek on Sat, 02 April 2022 01:31
|
 |
|
Re: Value with type float
By: mirek on Sat, 02 April 2022 01:31
|
 |
|
Re: Value with type float
By: mirek on Sat, 02 April 2022 09:43
|
 |
|
Re: Value with type float
By: Tom1 on Sat, 02 April 2022 10:55
|
 |
|
Re: Value with type float
By: mirek on Sat, 02 April 2022 11:26
|
 |
|
Re: Value with type float
By: Tom1 on Sat, 02 April 2022 13:31
|
 |
|
Re: Value with type float
By: mirek on Mon, 11 April 2022 16:52
|
 |
|
Re: Value with type float
By: Tom1 on Tue, 12 April 2022 09:26
|
 |
|
Re: Value with type float
By: mirek on Tue, 12 April 2022 13:40
|
 |
|
Re: Value with type float
By: Tom1 on Tue, 12 April 2022 13:54
|
 |
|
Re: Value with type float
By: Tom1 on Tue, 10 May 2022 13:21
|
 |
|
Re: Value with type float
By: mirek on Tue, 10 May 2022 15:44
|
 |
|
Re: Value with type float
By: Tom1 on Tue, 10 May 2022 20:08
|
 |
|
Re: Value with type float
By: mirek on Tue, 10 May 2022 21:26
|
 |
|
Re: Value with type float
By: Tom1 on Wed, 11 May 2022 08:20
|
 |
|
Re: Value with type float
By: mirek on Fri, 03 June 2022 10:52
|
 |
|
Re: Value with type float
By: Tom1 on Fri, 03 June 2022 12:03
|
 |
|
Re: Value with type float
By: mirek on Wed, 04 October 2023 09:55
|
 |
|
Re: Value with type float
By: Tom1 on Wed, 04 October 2023 12:08
|
 |
|
Re: Value with type float
By: mirek on Fri, 06 October 2023 12:51
|
 |
|
Re: Value with type float
By: Tom1 on Fri, 06 October 2023 13:40
|
 |
|
Re: Value with type float
By: mirek on Fri, 06 October 2023 13:54
|
 |
|
Re: Value with type float
By: Tom1 on Fri, 06 October 2023 14:28
|
 |
|
Re: Value with type float
By: mirek on Mon, 30 October 2023 10:34
|
 |
|
Re: Value with type float
By: Tom1 on Mon, 30 October 2023 12:27
|
 |
|
Re: Value with type float
By: mirek on Mon, 30 October 2023 13:37
|
 |
|
Re: Value with type float
By: mirek on Fri, 01 April 2022 11:03
|
 |
|
Re: Value with type float
By: jimlef on Tue, 06 September 2022 01:41
|
 |
|
Re: Value with type float
By: Oblivion on Tue, 06 September 2022 22:42
|
 |
|
Re: Value with type float
By: jimlef on Thu, 08 September 2022 14:49
|
Goto Forum:
Current Time: Thu May 01 06:00:35 CEST 2025
Total time taken to generate the page: 0.00873 seconds
|