comp.lang.ada
 help / color / mirror / Atom feed
* Trivial question: how to avoid confusing sec, min, hour and day in a program?
@ 2021-09-05  6:56 reinert
  2021-09-05  7:27 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 11+ messages in thread
From: reinert @ 2021-09-05  6:56 UTC (permalink / raw)


Anybody with good ideas on how (in a simplest possible way) to avoid to confuse between representation of time as seconds, minutes, hours and days in an Ada program?  Standardize on internal representation of time as seconds (Float)?  I will delay to use complex approaches for physical units.

It is somewhere in my program natural/human to think in seconds whereas  minutes or hours feels more natural at other places (so the numerics is "human"). Example to illustrate: heart rate is "natural" to give in number per minute (not in number per second, hour or day). Time on work is normally given by hours (not seconds) etc..

reinert

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Trivial question: how to avoid confusing sec, min, hour and day in a program?
  2021-09-05  6:56 Trivial question: how to avoid confusing sec, min, hour and day in a program? reinert
@ 2021-09-05  7:27 ` Dmitry A. Kazakov
  2021-09-05 12:42   ` Niklas Holsti
  2021-09-06  7:20   ` ldries46
  0 siblings, 2 replies; 11+ messages in thread
From: Dmitry A. Kazakov @ 2021-09-05  7:27 UTC (permalink / raw)


On 2021-09-05 08:56, reinert wrote:
> Anybody with good ideas on how (in a simplest possible way) to avoid to confuse between representation of time as seconds, minutes, hours and days in an Ada program?

Just use the standard type Duration.

> It is somewhere in my program natural/human to think in seconds whereas  minutes or hours feels more natural at other places (so the numerics is "human"). Example to illustrate: heart rate is "natural" to give in number per minute (not in number per second, hour or day). Time on work is normally given by hours (not seconds) etc..

The user interface is responsible to convert anything to Duration and back.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Trivial question: how to avoid confusing sec, min, hour and day in a program?
  2021-09-05  7:27 ` Dmitry A. Kazakov
@ 2021-09-05 12:42   ` Niklas Holsti
  2021-09-06  7:20   ` ldries46
  1 sibling, 0 replies; 11+ messages in thread
From: Niklas Holsti @ 2021-09-05 12:42 UTC (permalink / raw)


On 2021-09-05 10:27, Dmitry A. Kazakov wrote:
> On 2021-09-05 08:56, reinert wrote:
>> Anybody with good ideas on how (in a simplest possible way) to avoid 
>> to confuse between representation of time as seconds, minutes, hours 
>> and days in an Ada program?
> 
> Just use the standard type Duration.


But note that:

- Duration is a fixed-point type, not floating point, so it has a fixed 
resolution, Duration'Small.

- The resolution and range of Duration are implementation-defined, and 
the standard does not guarantee much. RM 9.6(27) says:

"The implementation of the type Duration shall allow representation of 
time intervals (both positive and negative) up to at least 86400 seconds 
(one day); Duration'Small shall not be greater than twenty milliseconds."

(Aside: I wonder why this paragraph is not in RM A.1, "The Package 
Standard", where the Duration type is introduced.)

If you want your code to be portable, define your own type for "time in 
seconds", choosing the properties your application needs.

That said, I believe that GNAT versions typically provide a 64-bit 
Duration type that has enough precision and range for most applications 
dealing with times on human scales. But perhaps not on nuclear, 
geological or astrophysical scales.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Trivial question: how to avoid confusing sec, min, hour and day in a program?
  2021-09-05  7:27 ` Dmitry A. Kazakov
  2021-09-05 12:42   ` Niklas Holsti
@ 2021-09-06  7:20   ` ldries46
  2021-09-06  9:47     ` Dmitry A. Kazakov
  2021-09-08 22:00     ` Shark8
  1 sibling, 2 replies; 11+ messages in thread
From: ldries46 @ 2021-09-06  7:20 UTC (permalink / raw)


Op 5-9-2021 om 9:27 schreef Dmitry A. Kazakov:
> On 2021-09-05 08:56, reinert wrote:
>> Anybody with good ideas on how (in a simplest possible way) to avoid 
>> to confuse between representation of time as seconds, minutes, hours 
>> and days in an Ada program?
>
> Just use the standard type Duration.
>
>> It is somewhere in my program natural/human to think in seconds 
>> whereas  minutes or hours feels more natural at other places (so the 
>> numerics is "human"). Example to illustrate: heart rate is "natural" 
>> to give in number per minute (not in number per second, hour or day). 
>> Time on work is normally given by hours (not seconds) etc..
>
> The user interface is responsible to convert anything to Duration and 
> back.
>
I agree with Dimitry but I think the problem  is far bigger and not only 
in Ada but in every computer language. You cannot use packages written 
by others if you do not know the dimensions they use. For instance in 
mechanical engineering in Europe there is a general use of cm while in 
other countries they use inches and in aircraft engineering they use in 
Europe mostly mm.
In general the use of dimensioning system ( f.i. cgs -cm gram second) is 
different for different countries and application area's. Some factors 
used within calculations are even dependant in the dimensioning system.
It would be a good idea if a package was developed that can solve all 
these problems for instance by doing the calculations in one of the 
possible dimensioning systems automagically presenting the results in 
the dimension you choose.
Such a system must exist of a record for every value, that exist of at 
least  real values for the standard dimensioning system and the value in 
the dimensioning system you want, the factor between the two systems and 
the string containing the dimension, perhaps even more.
There should be functions for "+", "-", "*", "/" and sqrt. The 
calculation should be done for the value in the standard dimension while 
the input and output must be in the wanted system. Also the strings and 
factors must be changed when necessary.
I have already been thinking how but the problem are mostly in the 
strings and the fact that there are also dimensions that have  a lower 
limit (temperature) or have an offset (degrees Celcius, Reamur or 
Fahrenheit) or exist of several integer values (time).
I think that the potential of Ada of being independent of an operating 
system can be extended that way to independent of the dimensioning system.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Trivial question: how to avoid confusing sec, min, hour and day in a program?
  2021-09-06  7:20   ` ldries46
@ 2021-09-06  9:47     ` Dmitry A. Kazakov
  2021-09-06 13:06       ` ldries46
  2021-09-06 15:55       ` AdaMagica
  2021-09-08 22:00     ` Shark8
  1 sibling, 2 replies; 11+ messages in thread
From: Dmitry A. Kazakov @ 2021-09-06  9:47 UTC (permalink / raw)


On 2021-09-06 09:20, ldries46 wrote:
> Op 5-9-2021 om 9:27 schreef Dmitry A. Kazakov:
>> On 2021-09-05 08:56, reinert wrote:
>>> Anybody with good ideas on how (in a simplest possible way) to avoid 
>>> to confuse between representation of time as seconds, minutes, hours 
>>> and days in an Ada program?
>>
>> Just use the standard type Duration.
>>
>>> It is somewhere in my program natural/human to think in seconds 
>>> whereas  minutes or hours feels more natural at other places (so the 
>>> numerics is "human"). Example to illustrate: heart rate is "natural" 
>>> to give in number per minute (not in number per second, hour or day). 
>>> Time on work is normally given by hours (not seconds) etc..
>>
>> The user interface is responsible to convert anything to Duration and 
>> back.
>>
> I agree with Dimitry but I think the problem  is far bigger and not only 
> in Ada but in every computer language. You cannot use packages written 
> by others if you do not know the dimensions they use. For instance in 
> mechanical engineering in Europe there is a general use of cm while in 
> other countries they use inches and in aircraft engineering they use in 
> Europe mostly mm.

Why do you need that? If written in Ada, the value is of some separate 
numeric type you could not mix with other types.

> In general the use of dimensioning system ( f.i. cgs -cm gram second) is 
> different for different countries and application area's. Some factors 
> used within calculations are even dependant in the dimensioning system.
> It would be a good idea if a package was developed that can solve all 
> these problems for instance by doing the calculations in one of the 
> possible dimensioning systems automagically presenting the results in 
> the dimension you choose.

If calculations are involved, they are performed in SI, because 
otherwise you need factors in all formulae. And SI means no mm, but m, 
no km/h, but m/s etc.

> Such a system must exist of a record for every value, that exist of at 
> least  real values for the standard dimensioning system and the value in 
> the dimensioning system you want, the factor between the two systems and 
> the string containing the dimension, perhaps even more.
> There should be functions for "+", "-", "*", "/" and sqrt.

    http://www.dmitry-kazakov.de/ada/units.htm

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Trivial question: how to avoid confusing sec, min, hour and day in a program?
  2021-09-06  9:47     ` Dmitry A. Kazakov
@ 2021-09-06 13:06       ` ldries46
  2021-09-06 13:43         ` J-P. Rosen
  2021-09-06 15:55       ` AdaMagica
  1 sibling, 1 reply; 11+ messages in thread
From: ldries46 @ 2021-09-06 13:06 UTC (permalink / raw)


Op 6-9-2021 om 11:47 schreef Dmitry A. Kazakov:
> On 2021-09-06 09:20, ldries46 wrote:
>> Op 5-9-2021 om 9:27 schreef Dmitry A. Kazakov:
>>> On 2021-09-05 08:56, reinert wrote:
>>>> Anybody with good ideas on how (in a simplest possible way) to 
>>>> avoid to confuse between representation of time as seconds, 
>>>> minutes, hours and days in an Ada program?
>>>
>>> Just use the standard type Duration.
>>>
>>>> It is somewhere in my program natural/human to think in seconds 
>>>> whereas  minutes or hours feels more natural at other places (so 
>>>> the numerics is "human"). Example to illustrate: heart rate is 
>>>> "natural" to give in number per minute (not in number per second, 
>>>> hour or day). Time on work is normally given by hours (not seconds) 
>>>> etc..
>>>
>>> The user interface is responsible to convert anything to Duration 
>>> and back.
>>>
>> I agree with Dimitry but I think the problem  is far bigger and not 
>> only in Ada but in every computer language. You cannot use packages 
>> written by others if you do not know the dimensions they use. For 
>> instance in mechanical engineering in Europe there is a general use 
>> of cm while in other countries they use inches and in aircraft 
>> engineering they use in Europe mostly mm.
>
> Why do you need that? If written in Ada, the value is of some separate 
> numeric type you could not mix with other types.

I do need that because you can use the same packages in different 
trades. If you want to calculate the inertia of a construction dependent 
on the location or the trade you are working in you use different 
dimension systems. Indeed you can use SI but most mechanical engineers 
use the cm as a basic unit while aeronautical engineers use the mm as 
there basic unit and the result differ with 4 zero's. In the USA they 
probably use inches which differ some incredible factors. if an American 
uses a European standard HE100 element in his calculations he has first 
to recalculate all inertia values. This will lead to greater error 
possibilities.
>
>> In general the use of dimensioning system ( f.i. cgs -cm gram second) 
>> is different for different countries and application area's. Some 
>> factors used within calculations are even dependant in the 
>> dimensioning system.
>> It would be a good idea if a package was developed that can solve all 
>> these problems for instance by doing the calculations in one of the 
>> possible dimensioning systems automagically presenting the results in 
>> the dimension you choose.
>
> If calculations are involved, they are performed in SI, because 
> otherwise you need factors in all formulae. And SI means no mm, but m, 
> no km/h, but m/s etc.
Sorry but It should perhaps be so but it is not. Programs made primarily 
for Aircraft engineering (f.i. CATIA 5/6) do use mm and your velocity 
clock in your car shows km/h and it registers the distance in km (in 
England and the USA mph and miles) In aircraft the Speed is often still 
measured in Knots (Nautical miles per hour). Maybe French aircraft will 
possibly show km/h. It is to hazardous to change this
>
>
>> Such a system must exist of a record for every value, that exist of 
>> at least  real values for the standard dimensioning system and the 
>> value in the dimensioning system you want, the factor between the two 
>> systems and the string containing the dimension, perhaps even more.
>> There should be functions for "+", "-", "*", "/" and sqrt.
>
>    http://www.dmitry-kazakov.de/ada/units.htm
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Trivial question: how to avoid confusing sec, min, hour and day in a program?
  2021-09-06 13:06       ` ldries46
@ 2021-09-06 13:43         ` J-P. Rosen
  2021-09-06 14:13           ` ldries46
  0 siblings, 1 reply; 11+ messages in thread
From: J-P. Rosen @ 2021-09-06 13:43 UTC (permalink / raw)


Le 06/09/2021 à 15:06, ldries46 a écrit :
>> If calculations are involved, they are performed in SI, because 
>> otherwise you need factors in all formulae. And SI means no mm, but m, 
>> no km/h, but m/s etc.
> Sorry but It should perhaps be so but it is not. Programs made primarily 
> for Aircraft engineering (f.i. CATIA 5/6) do use mm and your velocity 
> clock in your car shows km/h and it registers the distance in km (in 
> England and the USA mph and miles) In aircraft the Speed is often still 
> measured in Knots (Nautical miles per hour). Maybe French aircraft will 
> possibly show km/h. It is to hazardous to change this

Do not confuse computations with input/output. I agree with Dmitry, all 
computations should be performed in SI, with a (user selectable) choice 
of units for input and display.

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52
https://www.adalog.fr

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Trivial question: how to avoid confusing sec, min, hour and day in a program?
  2021-09-06 13:43         ` J-P. Rosen
@ 2021-09-06 14:13           ` ldries46
  2021-09-06 15:10             ` Dennis Lee Bieber
  0 siblings, 1 reply; 11+ messages in thread
From: ldries46 @ 2021-09-06 14:13 UTC (permalink / raw)


Op 6-9-2021 om 15:43 schreef J-P. Rosen:
> Le 06/09/2021 à 15:06, ldries46 a écrit :
>>> If calculations are involved, they are performed in SI, because 
>>> otherwise you need factors in all formulae. And SI means no mm, but 
>>> m, no km/h, but m/s etc.
>> Sorry but It should perhaps be so but it is not. Programs made 
>> primarily for Aircraft engineering (f.i. CATIA 5/6) do use mm and 
>> your velocity clock in your car shows km/h and it registers the 
>> distance in km (in England and the USA mph and miles) In aircraft the 
>> Speed is often still measured in Knots (Nautical miles per hour). 
>> Maybe French aircraft will possibly show km/h. It is to hazardous to 
>> change this
>
> Do not confuse computations with input/output. I agree with Dmitry, 
> all computations should be performed in SI, with a (user selectable) 
> choice of units for input and display.
>
What I tried to say is just what J-P Rosen says. But in my experience 
(41 years in aircraft engineering) that is not so, every time you have 
to realise what the system your working with and you are forced to even 
use systems parallel. One of the points I made the mechanical 
engineering which often uses cm has standard profiles using mm HE110B is 
100mm high. That is the reason that I ask for a package which solves 
this problem for once and always and still gives the user the 
possibility to use all kind of dimesions

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Trivial question: how to avoid confusing sec, min, hour and day in a program?
  2021-09-06 14:13           ` ldries46
@ 2021-09-06 15:10             ` Dennis Lee Bieber
  0 siblings, 0 replies; 11+ messages in thread
From: Dennis Lee Bieber @ 2021-09-06 15:10 UTC (permalink / raw)


On Mon, 6 Sep 2021 16:13:36 +0200, ldries46 <bertus.dries@planet.nl>
declaimed the following:

>100mm high. That is the reason that I ask for a package which solves 
>this problem for once and always and still gives the user the 
>possibility to use all kind of dimesions

	So... a reimplementation of the HP-48 UNITS module... Which requires
all values to have a unit designation attached (eg: 1.6_km) and internally
probably tracks the input unit but converts to base (SI) units for
computations, then remaps to user input units for display.


-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
	wlfraed@ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Trivial question: how to avoid confusing sec, min, hour and day in a program?
  2021-09-06  9:47     ` Dmitry A. Kazakov
  2021-09-06 13:06       ` ldries46
@ 2021-09-06 15:55       ` AdaMagica
  1 sibling, 0 replies; 11+ messages in thread
From: AdaMagica @ 2021-09-06 15:55 UTC (permalink / raw)


Dmitry A. Kazakov schrieb am Montag, 6. September 2021 um 11:47:54 UTC+2:
> http://www.dmitry-kazakov.de/ada/units.htm

http://archive.adaic.com/tools/CKWG/Dimension/Dimension.html

You might try to improve one of those packages for your needs.

Don't know what HE110B is.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Trivial question: how to avoid confusing sec, min, hour and day in a program?
  2021-09-06  7:20   ` ldries46
  2021-09-06  9:47     ` Dmitry A. Kazakov
@ 2021-09-08 22:00     ` Shark8
  1 sibling, 0 replies; 11+ messages in thread
From: Shark8 @ 2021-09-08 22:00 UTC (permalink / raw)


On Monday, September 6, 2021 at 1:22:03 AM UTC-6, ldries46 wrote:
> It would be a good idea if a package was developed that can solve all 
> these problems for instance by doing the calculations in one of the 
> possible dimensioning systems automagically presenting the results in 
> the dimension you choose.
There's this package[-set] -- http://archive.adaic.com/tools/CKWG/Dimension/SI.html
which is really pretty nice, and addresses the concern.

> I have already been thinking how but the problem are mostly in the  strings
Strings are terrible, avoid thinking in strings; be about the data first and foremost.
Strings should, inasmuch as possible, be used only in your UI; e.g. given a MVC structure only the VIEW should deal with Strings.

> I think that the potential of Ada of being independent of an operating 
> system can be extended that way to independent of the dimensioning system.
Possibly, the problem is addressed interestingly in VHDL via "physical units" where you can define a type and then use units with a conversion factor.
Example:

Type Avoirdupois_Weight is range 0 to 1E9 units
   Grain;
   Dram  =    27.34375 Grain;
   Ounce =    16.0 Dram;
   Pound =    16.0 Ounce;
   Ton   = 2_000.0 Pound
end units Avoirdupois_Weight;

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-09-08 22:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-05  6:56 Trivial question: how to avoid confusing sec, min, hour and day in a program? reinert
2021-09-05  7:27 ` Dmitry A. Kazakov
2021-09-05 12:42   ` Niklas Holsti
2021-09-06  7:20   ` ldries46
2021-09-06  9:47     ` Dmitry A. Kazakov
2021-09-06 13:06       ` ldries46
2021-09-06 13:43         ` J-P. Rosen
2021-09-06 14:13           ` ldries46
2021-09-06 15:10             ` Dennis Lee Bieber
2021-09-06 15:55       ` AdaMagica
2021-09-08 22:00     ` Shark8

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox