나눗셈과 나머지 계산 함수

함수 div와 ldiv에 대한 구조체(div_t, ldiv_t)는 헤더 파일 <stdlib.h>에 정의되어 있다.

구분

함수 원형과 인자

함수 설명

나눗셈 나머지 함수

div_t div(int n, int denom)

두 정수로 나눗셈을 하고 몫과 나머지를 구조체(div_t)로 반환

ldiv_t ldiv(long n, long denom)

long 형 정수로 나눗셈을 하고 몫과 나머지를 구조체(ldiv_t)로 반환

double modf(double x, double *inptr)

실수 x를 정수 부분과 실수 부분으로 분해

double fmod(double x, double y)

실수 x를 실수 y로 나눈 나머지를 계산


예제

 

 

#include<stdio.h>

#include<stdlib.h>

#include<math.h>

 

int main(void)

{

        div_t ix;

        ldiv_t lx;

        double num=3674654.568, frct, intg;

        double x1=7.0, y1=2.0;

 

        ix=div(10,4);

        printf("10/4의결과몫: %d, 나머지: %d\n", ix.quot, ix.rem);

 

        lx=ldiv(100L, 30L);

        printf("100/30의결과몫: %ld. 나머지: %ld\n", lx.quot, lx.rem);

 

        frct=modf(num, &intg);

        printf("%lf의정수%lf, 실수: %lf \n", num, intg, frct);

        printf("%lf/%lf의나머지: %lf\n", x1, y1, fmod(x1, y1));

 

        return 0;

}





정수 부분과 소수 이하 부분을 분리(modf함수 자세히)

modf

함수 원형

double modf(double x, double *inptr);

함수 인자

x, *inptr

double x는 분해의 대상이 되는 실수

inptr은 정수 부분을 반환받는 변수

반환 값

정수 부분을 제외한 실수를 반환


예제

 

 

#include<stdio.h>

#include<math.h>

 

int main(void)

{

    double num=334824.123, frct, intg;

 

    frct=modf(num, &intg);

    printf("입력된실수: %lf\n", num);

    printf("정수부분   : %lf\n", intg);

    printf("소수부분   : %lf\n", frct);

 

    return 0;

}

출처 : http://bestheroz.blog.me/109772856

'man' 카테고리의 다른 글

tty_ioctl(4) - Linux man page  (0) 2009.07.27
init_bh, remove_bh, mark_bh, disable_bh, enable_bh  (0) 2009.07.26

WRITTEN BY
RootFriend
개인적으로... 나쁜 기억력에 도움되라고 만들게되었습니다.

,

tty_ioctl(4) - Linux man page

man 2009. 7. 27. 17:31

<Exclusive mode>

TIOCEXCL void
Put the tty into exclusive mode. No further open(2) operations on the terminal are permitted. (They will fail with EBUSY, except for root.)
TIOCNXCL void
Disable exclusive mode

<Line discipline>

TIOCGETD int *argp
          Get the line discipline of the tty.
TIOCSETD const int *argp
Set the line discipline of the tty.

'man' 카테고리의 다른 글

C언어. 나눗셈, 나머지 계산 함수들  (0) 2010.09.07
init_bh, remove_bh, mark_bh, disable_bh, enable_bh  (0) 2009.07.26

WRITTEN BY
RootFriend
개인적으로... 나쁜 기억력에 도움되라고 만들게되었습니다.

,
       init_bh, remove_bh, mark_bh, disable_bh, enable_bh -
split-half interrupt handling


SYNOPSIS

       #include <linux/interrupt.h>

void init_bh(int nr, void (*routine)(void));
void remove_bh(int nr);
void mark_bh(int nr);
void disable_bh(int nr);
void enable_bh(int nr);


DESCRIPTION

   Theory
Split-half handling is a means of dividing an interrupt
handler into two sections, one of which (known as the `top
half') is time-critical and one of which (the `bottom
half') is not.

The top half (the handler registered with request_irq(9))
normally moves data between the device and a memory
buffer, ensures that the device is in a sane state, and
little else. While the top half of a handler is running,
the IRQ is question is blocked; if it is a fast interrupt
handler (i.e., it has SA_INTERRUPT set), all interrupts
are disabled.

The bottom half does whatever remains to be done. Bottom
halves run with interrupts enabled, although a locking
mechanism ensures that only one bottom half will be run�
ning at a given time. Bottom halves are run by
do_bottom_half(), which is called from schedule() and
ret_from_sys_call().

Usage
init_bh() installs routine() as bottom half number nr. It
operates by adding an entry to the bh_base[] table, and
setting the appropriate bit of the bh_mask vector. Rather
than specifying a number explicitly, one should add an
entry to the anonymous enum in include/linux/interrupt.h.

remove_bh() removes bottom half number nr from the list of
bottom halves. It removes the entry from bh_base[] and
clears the appropriate bit of bh_mask.

mark_bh() requests that the kernel run the specified bot�
tom half at the first available opportunity. This
function is normally called from the top half of an inter�
rupt handler. It operates by setting the appropriate bit
of the bh_active vector.

disable_bh() disables bottom half number nr by clearing
nested calls to disable_bh() must be matched by an equal
number of calls to enable_bh().

enable_bh() enables a bottom half previously disabled by
disable_bh(). This function decrements bh_mask_count[nr].
Then, if that value is zero, the specified bottom half is
enabled by setting the appropriate bit of bh_mask.


RETURN VALUE

       No value is returned.


AVAILABILITY

       Linux 2.0+.  init_bh() and remove_bh() were not present in
older versions on Linux. Under those versions, bh_base[]
and bh_mask must be modified by hand.


SEE ALSO

       request_irq(9), queue_task(9)

include/asm*/softirq.h, include/linux/interrupt.h, ker�
nel/softirq.c

"Kernel Korner" in issue 26 of The Linux Journal includes
a discussion of split-half interrupts under Linux. An
online copy of this article can be found at
http://www.ssc.com/lj/issue26/interrupt.html.


AUTHOR

       Neil Moore <amethyst@maxwell.ml.org>


BUGS

       Only 32 bottom halves are allowed.  Increasing this number
requires changing the size of bh_base[] and
bh_mask_count[] in kernel/softirq.c, and changing
bh_active and bh_mask (in the same file) to a larger type.
A better solution, however, would be to consolidate multi�
ple bottom halves into a single one by using task queues.
See queue_task(9) for details.














'man' 카테고리의 다른 글

C언어. 나눗셈, 나머지 계산 함수들  (0) 2010.09.07
tty_ioctl(4) - Linux man page  (0) 2009.07.27

WRITTEN BY
RootFriend
개인적으로... 나쁜 기억력에 도움되라고 만들게되었습니다.

,