Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-08

special numbers detected by val()

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marc Santhoff

Hi,

is there any special handling of NaN's or +/-INF's built into the VAL-procedure?

If so, where is it? ;)

You ask why? Okay:

I want to read in text files containing matrix data. The data is organized in rectangular manner, but some places are not valid because they are from physical measurements at places that are not reachable by any instrument.

In this data files I have to use a convention to detect this invalid spots.

My idea was to uses the string "NaN" or the like because anything else would narrow the range of input values (e.g. using -999 or similar for expressing the special case). If val could handle this itself, I'd not have to write any parsing code.

TIA,
Marc

Reply by email

Joao Morais
to Marc Santhoff: is there any special handling of NaN's or +/-INF's built into the VAL-procedure? If so,…
Marc Santhoff wrote 12 lines
I want to read in text files containing matrix data. The data is organized in rectangular manner, but some places are not valid because they are from physical measurements at places that are not reachable by any instrument. In this data files I have to use a convention to detect this invalid spots. My idea was to uses the string "NaN" or the like because anything else would narrow the range of input values (e.g. using -999 or similar for expressing the special case). If val could handle this itself, I'd not have to write any parsing code.

You can implement your own data type (eg as a class) and include some flags as IsNull, IsEmpty, etc.

Joao Morais

Reply by email

Marc Santhoff
to Joao Morais
Joao Morais wrote 16 lines
Marc Santhoff wrote: > I want to read in text files containing matrix data. The data is > organized in rectangular manner, but some places are not valid because > they are from physical measurements at places that are not reachable by > any instrument. > > In this data files I have to use a convention to detect this invalid > spots. > > My idea was to uses the string "NaN" or the like because anything else > would narrow the range of input values (e.g. using -999 or similar for > expressing the special case). If val could handle this itself, I'd not > have to write any parsing code. You can implement your own data type (eg as a class) and include some flags as IsNull, IsEmpty, etc.

I would, but it wouldn't fit the existing program that is intended to use these values.

I simply made a new procedure that evaluates the special strings and calls system.val() if none is found. Once these values are parsed "NaN" and "Infinity" can be used as float values. So far this seems to work and gives a good source for exceptions, too.

Thank you and thanks to Jonas for answering quickly, Marc

Reply by email