Forum > General

Missing IsInfinite function for extended

(1/3) > >>

Gammatester:
Why is there no IsInfinite function for extended? (Like IsNan, which is implemented for single, double, extended). The following function for Win32 for i386 crashes:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program isinfx;uses  math;var  x: extended;begin  x := 1e2345;  writeln(IsInfinite(x));end.Here the output

--- Code: ---C:\TMP>D:\FPC304\bin\i386-win32\fpc.exe isinfx.pas
Free Pascal Compiler version 3.0.4 [2017/10/06] for i386
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling isinfx.pas
Linking isinfx.exe
11 lines compiled, 0.2 sec, 64432 bytes code, 4132 bytes data

C:\TMP>isinfx.exe
An unhandled exception occurred at $0040156D:
EOverflow: Floating point overflow
  $0040156D

--- End code ---
There is no such problem for singles because single-inf is compatible with double-inf.

Ñuño_Martínez:
Are you sure the exception is raised in line 8?  May be it is raised in line 7.  ::)

Anyway I've tested your code and it worked (FPC 3.0.0 + Xubuntu 16.04.4).

Gammatester:
Yes I am sure. If you change the source to

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program isinfx;uses  math;var  x: extended;begin  x := 1e2345;  writeln('Value of x:', x);  writeln('No crash up to now');  writeln(IsInfinite(x));end.You get
--- Code: ---Value of x: 9.99999999999999999980E+2344
No crash up to now
An unhandled exception occurred at $004015ED:
EOverflow: Floating point overflow
  $004015ED
--- End code ---
and no  crash if you omit the IsInfinite. The reason is clear: IsInfinite expects a double and  x (=1e2345) cannot converted to double.

--- Quote from: Ñuño_Martínez on May 28, 2018, 01:47:05 pm ---Anyway I've tested your code and it worked (FPC 3.0.0 + Xubuntu 16.04.4).

--- End quote ---
What does this mean? Do you get an EOverflow as decribed? Otherwise do you compile a 64-bit-Exe? Then there are no 10-Bytes-Extended and the `x := 1e2345;` may crash, I get x=inf for 64-bit.

marcov:
I tested with the 32-bit development version of FPC (3.1.1 a few days old), and indeed I got an exception.

What did help for me is the extended class helper in sysutils:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---    program isinfx;    uses      sysutils;    var      x: extended;    begin      x := 1e2345;      writeln('Value of x:', x);      writeln('No crash up to now');      writeln(x.IsInfinity);    end.
Could be that that is a trunk feature though.

PascalDragon:
Just in case, I've added overloads for Single and Extended for IsInfinite() (Delphi has them as well).

Navigation

[0] Message Index

[#] Next page

Go to full version