Recent

Author Topic: Ranges for floats in declarations ?  (Read 218 times)

jamie

  • Hero Member
  • *****
  • Posts: 3236
Ranges for floats in declarations ?
« on: November 28, 2019, 07:11:51 pm »
I've gotten into using ranges for variables in the declaration section so the compiler can pick the smallest size needed for the job, today I decided to do that with a float number and it does not seem to work

For example
Var
MyDegreeAngle :0.0..359.9;

With that i can pick a single in most cases and also helps with debugging code.

Any flack on this ?

« Last Edit: November 28, 2019, 07:18:30 pm by jamie »
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 2955
Re: Ranges for floats in declarations ?
« Reply #1 on: November 28, 2019, 07:22:12 pm »
The problem with ranges for floats is that the range is efectively infinite, even if he limits are known.

What I do for those cases is to use a record + helper/method: the record contains the upper and lower limits and the helper/method test a float against those limits.

But, of course, that doesn't give you the type-selection you want; you'd still have to declare the type :(
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018