mirror of https://github.com/lianthony/NT4.0
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
1.5 KiB
87 lines
1.5 KiB
;/***
|
|
;*ceil.a -
|
|
;*
|
|
;* Copyright (c) 1991-91, Microsoft Corporation
|
|
;*
|
|
;*Purpose:
|
|
;*
|
|
;*
|
|
;*Revision History:
|
|
;*
|
|
;* 05-12-92 PLM written
|
|
;*/
|
|
;
|
|
;/***
|
|
;*double ceil(double x) - round to next highest integer
|
|
;*
|
|
;*Purpose:
|
|
;* Round to integer according to next highest integer.
|
|
;*
|
|
;*Entry:
|
|
;*
|
|
;*Exit:
|
|
;*
|
|
;*Exceptions:
|
|
;*******************************************************************************/
|
|
;
|
|
;
|
|
;double ceil(double x)
|
|
|
|
#include <traps.a>
|
|
#include <sane.a>
|
|
#include <trans.a>
|
|
|
|
|
|
cProc ceil,PUBLIC
|
|
parmQ x
|
|
localV xlocalx,10
|
|
localW xtestw
|
|
localD fpstat
|
|
cBegin ceil
|
|
#ifdef SANE
|
|
pea fpstat ;get current control word
|
|
move.w #FOGETENV,-(a7)
|
|
FP68K
|
|
|
|
pea x
|
|
pea xlocalx
|
|
move.w #FFDBL+FOZ2X,-(a7)
|
|
FP68K ;convert to extended
|
|
|
|
move.w fpstat,d0 ;save current control word
|
|
move.w #IRC_UP,fpstat ;set sounding to up
|
|
pea fpstat ;set new control word
|
|
move.w #FOSETENV,-(a7)
|
|
FP68K
|
|
pea xlocalx
|
|
move.w #FORTI,-(a7)
|
|
FP68K ;round result
|
|
|
|
move.w d0,fpstat ;restore control word
|
|
lea xlocalx,a1
|
|
move.w (a1)+,d0 ;load result for return
|
|
move.l (a1)+,d1
|
|
move.l (a1),a0
|
|
|
|
pea fpstat
|
|
move.w #FOPROCEXIT,-(a7)
|
|
FP68K
|
|
|
|
#else
|
|
fmove.l fpcr,d0 ;save current control word
|
|
|
|
fmove.d x, fp0
|
|
ftst.x fp0 ;see if it is a valid number
|
|
fmove.l fpsr, d1 ;get status word
|
|
and.l #0x03007c00, d1 ;see if we get an exception
|
|
cmp.l #0, d1
|
|
ifneq
|
|
jbsr __Domain_error ; if not equal, domain error
|
|
else
|
|
fmove.l #IRC_UP,fpcr ;set rounding mode to up
|
|
fint.d x,fp0 ;round it up
|
|
endif
|
|
fmove.l d0,fpcr ;restore control word
|
|
#endif
|
|
cEnd ceil
|
|
|