In Delphi, what is the keyword for the maximum value for a floating point type?

Note. This question has been edited because my problem has become something completely different. You will find a direct answer to the question What the keyword for the maximal value for a floating point type? in MBo answer - use System.Math constants.

Delphi provides several types of floating point values. There are Single, Double and Extended to start with.

Last week, I looked at which keyword 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 an expected exit

 float1 = INF float2 = 23 float1 - float2 = INF -float1 = -INF 

I have a form with a component on it. This component has a couple of attributes. If I use the property editor to put Infinity as the value for the floating point attribute, I get an error that this is an invalid floating point value. The same goes for INF .

Then I typed 9.9E308 in the MaxValue field. He transformed into INF .

Form attribute

Feeling quite pleased with this, I kept my form and continued my work. I compiled the form later that day, having successfully verified that the form may contain the value 1E308 .

The next day...

Error on restarting IDE

Opening a .dfm file in notepad gives me the following:

 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 does this automatically change 9.9E308 to INF, compile successfully, save successfully, but not load? Is this a bug in my IDE? I am using Embarcadero® Delphi® XE5 version 19.0.14356.6604, 32 bit in Windows 7.

+6
source share
1 answer

The System.Math module contains the Infinity constant for representing the IEEE754 Inf pseudo-service (1.0 / 0.0). There are also many constants MaxDouble, MaxExtended, etc. in this block. (See the Variables section here . ) This short test works as needed, so I suspect your component may have some range checking or have a property editor that does not understand unknown identifiers.

  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; 

PS Do you need to use the Infinity value as a field value or just to have a field value> -1E300?

PPS Why are you still using INF and not Infinity? BTW, I found one component with a published float property - Object Inspector does not understand Infinity - therefore, the property editor is not intended for these purposes , as I already expected, but I can assign Infinity in the code.

+5
source

All Articles