コンテンツにスキップ

端数処理

出典: フリー百科事典『ウィキペディア(Wikipedia)』
シャープ Compet CS-2122L上の丸めセレクタ。左のツマミで切り上げ・四捨五入・切り捨てのいずれかを選択し、右のツマミで小数点以下の桁数を選択する。事務用電卓の中には、この機種のように計算結果を指定した桁数に丸めて表示できるものもある。



101001010.10.01N

[]

[]


1#0.1


[]


0010

4

00 (rounding toward zero; RZ) (rounding toward infinity; RI)

 (rounding toward minus infinity; RM) (rounding toward plus infinity; RP)

11使

使








[]


2 (round to the nearest)

0.5[0, 1)0.50.5


[]


0.50.5JIS Z 8401B[1]45R

0.50210.50.51.51JIS Z 84011.520.5[1]

0.5

[]


0.50.5

0.5

0.5

round to even[]


round to even[2][3]0.50.50.5(+0.5+0.5JIS Z 8401AB[1]

0.5+0.5+0.5

JIS Z 8401 JIS[4]ISO 31-0ISO使 (bankers' rounding)[ 1]50.5[ 2]

round to odd[]


round to odd[2]0.50.50.5

0.5+0.5+0.5

[]



[]


56[ 3]

0.40.550使

0.10.10.50.60.90.50.6

0.11001000

使0

[]


#

[]




533

15

IEEE[]


IEEE 754



0





4IEEE

[]

[]


[0,1)



10

00.5

使

[]




LSB


2[]


2

122.51  123  122.5  122 

123.49  123  123.5  124 

 + 0.50.50.5 + 0.5[ 4]

[]


0.1[ 5]
与えられた数値 切り捨て 切り上げ 四捨五入 五捨六入 偶数への丸め
8.05 8.0 8.1 8.1 8.0 8.0
8.051 8.0 8.1 8.1 8.0 8.1
8.15 8.1 8.2 8.2 8.1 8.2
8.25 8.2 8.3 8.3 8.2 8.2
8.263 8.2 8.3 8.3 8.3 8.3
8.347 8.3 8.4 8.3 8.3 8.3
8.35 8.3 8.4 8.4 8.3 8.4
8.45 8.4 8.5 8.5 8.4 8.4


[]

[]


chopping02

chopping0321616使

choppingLSB

[]


FPU

12

RubyPHP 0.1  0.11 1 0.1  0.1 [5]

32

floor, ceiling, truncate[]

floorceil

0使

 - floor

 - ceilceiling

 - trunctruncatefix

5IEEE3

: ±3.7 1

ceil(3.7) = 4, ceil(-3.7) = -3

floor(3.7) = 3, floor(-3.7) = -4

trunc(3.7) = 3, trunc(-3.7) = -3

round[]


round[ 6]
プログラミング言語 round(0.5) round(-0.5)
C99
C++11

Ruby

1 -1
.NET Framework
Python
0 0
Java 1 0
JavaScript 1 -0

C言語における型変換と端数処理[編集]

演算子(int)



Cmodf0

§a.b JIS X 3010-1993C89

C§6.2.1.30

C89§7.5floorceil§7.5.6

C99roundfegetround/fesetroundmath.hfenv.h

 (int)(0.6/0.2)  3.0  2.0  0.6  0.2 0.6/0.2  2.9999999999999996 

テーブルメーカーのジレンマ (数表作成者のジレンマ)[編集]


[ 7]#2[6]



 y^w 21/2ulp1ulp y^w 1/2ulp?...()

IEEE75419851985bit1ULP2008

GelfondSchneiderLindemannWeierstrass



GNU MPFR



IBMlibultim ()

Sun Microsystemslibmcr (4)

Arénaire(LIP, ENS Lyon)CRlibm (4)

determined 42

10^n n420

n10

[]


[7]

1()2[8][9]51[?][10]32 P2823032

[9]  

m3mm m 3cm

3

1便

mm42215226. (6).2)3()

mm2m3t21100

[11]調

[12]44×23×11

脚注[編集]

注釈[編集]



(一)^ JISISO

(二)^ 

(三)^ 

(四)^ ...000  0  lexer XXX...XXX.5000000000000000000000001 

(五)^ JIS Z8401:2019, p.2, 2 e) 

(六)^ []MicrosoftC99C++11JavaECMAScript(JavaScript)

(七)^ 

[]



(一)^ abcJISZ8401 2019.

(二)^ ab"The Art of Computer Programming" D. E. Knuth (1997, § 4.2.2)The Art of Computer Programming Volume 2 Seminumerical algorithms Third Edition Donald E.Knuth2004ISBN 978-4-7561-4543-7 p.224 §4.2.2 (20041026 )

(三)^ C (UNIX & Information Science)    5 p.12 §1.5

(四)^    1989/4/26 1 6 p.208

(五)^ 210. Island Life. 20161223

(六)^ Jean-Michel Muller. Introduction to the Table Maker's Dilemma. 2019310

(七)^ 
.   (26221). 2019920[] 

.   (H23.10.1). 2019920


(八)^ ().  . 2019920

(九)^ ab.  . 2019920

(十)^ 
3010 .  . 20211202019920

.  . 2019920

.  . 2019920[]


(11)^ .  . 2019919

(12)^  (30-03-20). .  . 20191016

[]

[]


JIS Z 8401:2019調

[]