[clean-list] Maybe I should change my job and apply for the pope-position

Fabien Todescato f.todescato@larisys.fr
Fri, 12 Oct 2001 15:17:47 +0200


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_000_01C15320.496F89F0
Content-Type: text/plain;
	charset="iso-8859-1"

Siegfried Gonzi wrote :

> Fabien Todescato wrote:
> 
>> PS.I may send you the sources privately, although it is certainly not a
>> brilliant piece of software...
>
>highly appreciated.
>
>Please, post it also officially. I think it is of great help.
>
>Thank you,
>Siegfried Gonzi

There you are, and let god forgive me.

Best regards, Fabien TODESCATO



------_=_NextPart_000_01C15320.496F89F0
Content-Type: application/octet-stream;
	name="tslReal.dcl"
Content-Disposition: attachment;
	filename="tslReal.dcl"

definition module tslReal

from StdEnv import String

// --------------------------------------------------------------------------------
toStringTSLReal :: .Int !.Real -> String
// --------------------------------------------------------------------------------
// toStringTSLReal n x is the string representation of the real number x formatted
// according to the TSL standard, with a total number of n digits, including the
// integer and fractional part, but excluding the decimal separator.
// --------------------------------------------------------------------------------

// --------------------------------------------------------------------------------
toStringTSLReal1 :: .Int !.Int .Real -> String
// --------------------------------------------------------------------------------
// toStringTSLReal1 n m x is the string representation of the real number x
// formatted according to the TSL standard, with a number of n fractional digits.
// The number is bumped to the right and packed witj spaces so as to occupy m
// characters in all.
// --------------------------------------------------------------------------------

// --------------------------------------------------------------------------------
toStringTSLReal2 :: !.Int .Real -> String
// --------------------------------------------------------------------------------
// toStringTSLReal2 n x is the string representation of the integer part of the real
// number x. In case the integer part needs less than n digit to be represented,
// spaces are appended to the left so that exactly n characters are used.
// The number x is supposed to be non-negative.
// --------------------------------------------------------------------------------

// --------------------------------------------------------------------------------
bumpedLeftString :: ! Int String -> String
// --------------------------------------------------------------------------------
// bumpedLeftString n s is the string s truncated to n characters. If the string s
// has more than n characters, it is completed to the right with spaces, so that
// the resulting string always has n characters.
// --------------------------------------------------------------------------------

// --------------------------------------------------------------------------------
bumpedRightString :: ! Int String -> String
// --------------------------------------------------------------------------------
// bumpedRightString n s is the string s truncated to n characters. If the string s
// has more than n characters, it is completed to the left with spaces, so that
// the resulting string always has n characters.
// --------------------------------------------------------------------------------

------_=_NextPart_000_01C15320.496F89F0
Content-Type: application/octet-stream;
	name="tslReal.icl"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="tslReal.icl"

implementation module tslReal

from arrays import listToCharUnboxedArray // Private array utility =
module.

from StdEnv import String , +++ , while , < , ~ , =3D=3D , > , / , =
toString , toInt , entier , + , - , o , <> , mod , not , * , toChar , =
toReal , map , snd , take , length , iter , ^ , ++ , repeat , repeatn

toStringTSLReal :: .Int !.Real -> String
toStringTSLReal n r
  =3D if ( rNormalized =3D=3D 0.0 ) "0" ( signPart +++ integerPart +++ =
fractionalPart +++ exponentPart )
where
  ( rSign , rNormalized , rExponent )
    =3D normalized r
  rInteger
    =3D entier rNormalized
  rIntegerDigits
    =3D ( map ( toChar o (+) 48 ) o snd o while ( \ ( i , _ ) -> i <> 0 =
) ( \ ( i , l ) -> ( i / 10 , [ i mod 10 : l ] ) ) ) ( rInteger , [ ] )
  rIntegerDigitsCount
    =3D length rIntegerDigits
  rFractional n
    =3D toInt ( ( rNormalized - toReal rInteger ) * 10.0^toReal n )
  rFractionalDigits n
    =3D ( map ( toChar o (+) 48 ) o snd o iter n ( \ ( i , l ) -> ( i / =
10 , [ i mod 10 : l ] ) ) ) ( rFractional n , [ ] )
  signPart
  =3D if ( rSign < 0.0 ) "-" ""
  exponentPart
  =3D if ( rExponent =3D=3D 0 ) "" ( "E" +++ toString rExponent )
  integerPart
    =3D if ( rInteger =3D=3D 0 ) "" ( listToCharUnboxedArray =
rIntegerDigits )
  fractionalPart
    =3D "." +++ listToCharUnboxedArray ( rFractionalDigits ( n - =
rIntegerDigitsCount ) )

toStringTSLReal1 :: .Int !.Int .Real -> String
toStringTSLReal1 n m r
  =3D bumpedRightString m ( if ( rNormalized =3D=3D 0.0 ) "0" ( =
signPart +++ integerPart +++ fractionalPart +++ exponentPart ) )
where
  ( rSign , rNormalized , rExponent )
    =3D normalized r
  rInteger
    =3D entier rNormalized
  rIntegerDigits
    =3D ( map ( toChar o (+) 48 ) o snd o while ( \ ( i , _ ) -> i <> 0 =
) ( \ ( i , l ) -> ( i / 10 , [ i mod 10 : l ] ) ) ) ( rInteger , [ ] )
  rFractional n
    =3D toInt ( ( rNormalized - toReal rInteger ) * 10.0^toReal n )
  rFractionalDigits n
    =3D ( map ( toChar o (+) 48 ) o snd o iter n ( \ ( i , l ) -> ( i / =
10 , [ i mod 10 : l ] ) ) ) ( rFractional n , [ ] )
  signPart
  =3D if ( rSign < 0.0 ) "-" ""
  exponentPart
  =3D if ( rExponent =3D=3D 0 ) "" ( "E" +++ toString rExponent )
  integerPart
    =3D if ( rInteger =3D=3D 0 ) "0" ( listToCharUnboxedArray =
rIntegerDigits )
  fractionalPart
    =3D "." +++ listToCharUnboxedArray ( rFractionalDigits n )

normalized r
  =3D ( rSign , rNormalized , rExponent )
where
  ( rSign , rMagnitude )
  =3D if ( r < 0.0 ) ( (-1.0) , ~r ) ( (+1.0) , r )
  ( rNormalized , rExponent )
  =3D if ( rMagnitude =3D=3D 0.0 )
       ( 0.0 , 0 )
       ( ( while ( \ ( x , _ ) -> x > 1.0E+4 ) ( \ ( x , e ) -> ( x / =
1.0E+3 , e + 3 ) )
         o while ( \ ( x , _ ) -> x < 1.0E-3 ) ( \ ( x , e ) -> ( x / =
1.0E-3 , e - 3 ) )
         )
         ( rMagnitude , 0 )
       )

toStringTSLReal2 :: !.Int .Real -> String
toStringTSLReal2 n r
  =3D listToCharUnboxedArray ( take n ( repeatn ( n - =
rIntegerDigitsCount ) ' ' ++ rIntegerDigits ) )
where
  rInteger
    =3D entier r
  rIntegerDigits
    =3D if ( rInteger =3D=3D 0 )
         ['0']
         ( ( map ( toChar o (+) 48 ) o snd o while ( \ ( i , _ ) -> i =
<> 0 ) ( \ ( i , l ) -> ( i / 10 , [ i mod 10 : l ] ) ) ) ( rInteger , =
[ ] ) )
  rIntegerDigitsCount
    =3D length rIntegerDigits

bumpedLeftString :: ! Int String -> String
bumpedLeftString n s =3D listToCharUnboxedArray ( take n ( arrayToList =
s ++ repeat ' ' ) )

bumpedRightString :: ! Int String -> String
bumpedRightString n s =3D listToCharUnboxedArray ( take n ( repeatn ( n =
- size s ) ' ' ++ arrayToList s ) )

------_=_NextPart_000_01C15320.496F89F0--