Vag Vagoff wrote:
>Very important procedures seems to be missing in Clean standard library:
>
>    floor :: !Real -> Real
>    ceiling :: !Real -> Real
>
>How to fix that?

If the result can fit in an Int use fromInt or toReal and:

entier :: !Real -> Int

to implement floor. Use

~ (entier (~ x))

to compute the ceiling of x.

On a 64 bit computer no rounding is necessary for Real's that are
too large for type Int. So depending on the size use fromInt and entier,
or do nothing.

On computers using the 32 bit intel/AMD instruction set, you can use:

floorR_IA32 :: !Real -> Real;
floorR_IA32 r = code {
        | 83 ec 08                sub    $0x8,%esp
        instruction 131
        instruction 236
        instruction 8
        | 9b d9 3c 24             fstcw  (%esp)
        instruction 155
        instruction 217
        instruction 60
        instruction 36
        | 66 8b 04 24             mov    (%esp),%ax
        instruction 102
        instruction 139
        instruction 4
        instruction 36
        | 66 25 ff f3             and    $0xf3ff,%ax
        instruction 102
        instruction 37
        instruction 255
        instruction 243
        | 66 0d 00 04             or     $0x400,%ax
        instruction 102
        instruction 13
        instruction 0
        instruction 4
        | 66 89 44 24 02          mov    %ax,0x2(%esp)
        instruction 102
        instruction 137
        instruction 68
        instruction 36
        instruction 2
        | d9 6c 24 02             fldcw  0x2(%esp)
        instruction 217
        instruction 108
        instruction 36
        instruction 2
        | d9 fc                   frndint
        instruction 217
        instruction 252
        | d9 2c 24                fldcw  (%esp)
        instruction 217
        instruction 44
        | 83 c4 08                add    $0x8,%esp
        instruction 36
        instruction 131
        instruction 196
        instruction 8
}

ceilR_IA32 :: !Real -> Real;
ceilR_IA32 r = code {
        | 83 ec 08                sub    $0x8,%esp
        instruction 131
        instruction 236
        instruction 8
        | 9b d9 3c 24             fstcw  (%esp)
        instruction 155
        instruction 217
        instruction 60
        instruction 36
        | 66 8b 04 24             mov    (%esp),%ax
        instruction 102
        instruction 139
        instruction 4
        instruction 36
        | 66 25 ff f3             and    $0xf3ff,%ax
        instruction 102
        instruction 37
        instruction 255
        instruction 243
        | 66 0d 00 04             or     $0x800,%ax
        instruction 102
        instruction 13
        instruction 0
        instruction 8
        | 66 89 44 24 02          mov    %ax,0x2(%esp)
        instruction 102
        instruction 137
        instruction 68
        instruction 36
        instruction 2
        | d9 6c 24 02             fldcw  0x2(%esp)
        instruction 217
        instruction 108
        instruction 36
        instruction 2
        | d9 fc                   frndint
        instruction 217
        instruction 252
        | d9 2c 24                fldcw  (%esp)
        instruction 217
        instruction 44
        | 83 c4 08                add    $0x8,%esp
        instruction 36
        instruction 131
        instruction 196
        instruction 8
}

Kind regards,

John van Groningen
_______________________________________________
clean-list mailing list
[email protected]
http://mailman.science.ru.nl/mailman/listinfo/clean-list

Reply via email to