Note: This question has been edited because my issue became something completely different. You'll find the direct answer to the question What's the keyword for the maximal value for a floating point type?
in MBo's answer - use System.Math's constants.
Delphi provides multiple floating point value types. There's Single, Double and Extended to start with.
Last week I looked up what the keyword is for the maximum floating point value and found this: http://www.delphibasics.co.uk/RTL.asp?Name=Infinity
var
float1, float2 : single;
begin
float1 := Infinity;
float2 := 23;
ShowMessage('float1 = '+FloatToStr(float1));
ShowMessage('float2 = '+FloatToStr(float2));
ShowMessage('float1 - float2 = '+FloatToStr(float1 - float2));
ShowMessage('-float1 = '+FloatToStr(-float1));
end;
With supposed output
float1 = INF
float2 = 23
float1 - float2 = INF
-float1 = -INF
I have a form with a component on it. This component has a couple attributes.
If I use the property editor to put Infinity
as value for the floating point attribute, I get the error that it is an invalid floating point value. Same goes for INF
.
Then I typed 9.9E308
into the MaxValue field. It transformed into INF
.
Feeling rather pleased about this, I saved my form and went on with my work. I compiled the form later that day, succesfully testing that the form could hold a value of 1E308
.
The next day...
Opening the .dfm file in notepad gives me this:
object gridDoubleEditor: TdgmrGridDoubleEdit
Tag = 0
WantKeyLeftRight = False
WantKeyUpDown = False
WantKeyHomeEnd = False
WantKeyPriorNext = False
EmptyString = '--'
EmptyValue = -1E300
MinValue = -1E300
MaxValue = INF
NumberOfDecimals = 2
Alignment = taRightJustify
Left = 336
Top = 208
end
How come it automatically changes 9.9E308
to INF, compiles succesfully, saves succesfully, but fails to load? Is this a bug in my IDE? I'm using Embarcadero® Delphi® XE5 Version 19.0.14356.6604, 32 bits on Windows 7.
Represents the largest possible value of Single. This field is constant. public: float MaxValue = 3.40282347E+38; C# Copy.
System.Math unit contains Infinity
constant to represent IEEE754 Inf pseudovalue(1.0/0.0). There are also a lot of MaxDouble, MaxExtended etc constants in this unit (look at Variables section here). This short test works as needed, so I suspect your component may have some kind of range checking or have property editor that don't understand unknown identificators.
TTest = class(TComponent)
private
FValue: Double;
procedure SetValue(const Value: Double);
public
property Value: Double read FValue write SetValue;
end;
procedure TForm1.Button26Click(Sender: TObject);
begin
with TTest.Create(Self) do try
Value := Infinity;
Caption := FloatToStr(Value);
finally
Free;
end;
end;
P.S. Do you need to use Infinity as field value, or just to ensure that field value > -1E300?
P.P.S. Why you are still using INF, not Infinity? BTW, I've found one component with float published property - Object Inspector don't understand Infinity - so property editor is not designed for these purposes, as I've already supposed, but I can assign Infinity in code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With