Changeset 030653a


Ignore:
Timestamp:
Jun 18, 2020, 6:58:33 PM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
91e52be
Parents:
c1ee231
Message:

add unit conversions from duration to double

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/time.hfa

    rc1ee231 r030653a  
    1010// Created On       : Wed Mar 14 23:18:57 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Feb  4 08:24:32 2020
    13 // Update Count     : 654
     12// Last Modified On : Wed Jun 17 16:13:00 2020
     13// Update Count     : 663
    1414//
    1515
     
    2020
    2121#include <time.h>                                                                               // timespec
    22 extern "C" {
    2322#include <sys/time.h>                                                                   // timeval
    24 }
    2523#include <time_t.hfa>                                                                   // Duration/Time types
    2624
     
    9189        int64_t ?`w( Duration dur ) { return dur.tn / (7LL * 24LL * 60LL * 60LL * TIMEGRAN); }
    9290
     91        double ?`dns( Duration dur ) { return dur.tn; }
     92        double ?`dus( Duration dur ) { return dur.tn / ((double)TIMEGRAN / 1_000_000.); }
     93        double ?`dms( Duration dur ) { return dur.tn / ((double)TIMEGRAN / 1_000.); }
     94        double ?`ds( Duration dur ) { return dur.tn / (double)TIMEGRAN; }
     95        double ?`dm( Duration dur ) { return dur.tn / (60. * TIMEGRAN); }
     96        double ?`dh( Duration dur ) { return dur.tn / (60. * 60. * (double)TIMEGRAN); }
     97        double ?`dd( Duration dur ) { return dur.tn / (24. * 60. * 60. * (double)TIMEGRAN); }
     98        double ?`dw( Duration dur ) { return dur.tn / (7. * 24. * 60. * 60. * (double)TIMEGRAN); }
     99
    93100        Duration max( Duration lhs, Duration rhs ) { return  (lhs.tn < rhs.tn) ? rhs : lhs;}
    94101        Duration min( Duration lhs, Duration rhs ) { return !(rhs.tn < lhs.tn) ? lhs : rhs;}
  • tests/.expect/time.txt

    rc1ee231 r030653a  
    1110800 2 3.375 12 1.00001
     20.125 0.0333333333333333 3.375 12000. 1000010.
    230 2 3.375
    347 7 7
  • tests/time.cfa

    rc1ee231 r030653a  
    1010// Created On       : Tue Mar 27 17:24:56 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jan  5 18:27:37 2020
    13 // Update Count     : 34
     12// Last Modified On : Thu Jun 18 18:14:49 2020
     13// Update Count     : 37
    1414//
    1515
     
    2020        Duration d1 = 3`h, d2 = 2`s, d3 = 3.375`s, d4 = 12`s, d5 = 1`s + 10_000`ns;
    2121        sout | d1 | d2 | d3 | d4 | d5;
     22        sout | d1`dd | d2`dm | d3`ds | d4`dms | d5`dus;
    2223        d1 = 0;
    2324        sout | d1 | d2 | d3;
Note: See TracChangeset for help on using the changeset viewer.