diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-02-19 08:16:34 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-02-19 08:16:34 +0000 |
commit | 45d282aeb06dc76904c4c2e13807fc315e0e0911 (patch) | |
tree | 082d04f3eeebd86bb9d78c69868b0de2c2eec12f /ext/bigdecimal | |
parent | ac5565317c406c227a439f01174ed165b67d89f9 (diff) |
* ext/socket/socket.c (unix_peeraddr): wrong syscall name in error
message for #peeraddr. a patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:10366]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@11777 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal')
-rw-r--r-- | ext/bigdecimal/bigdecimal.c | 44 | ||||
-rw-r--r-- | ext/bigdecimal/bigdecimal.h | 12 | ||||
-rw-r--r-- | ext/bigdecimal/bigdecimal_en.html | 9 | ||||
-rw-r--r-- | ext/bigdecimal/bigdecimal_ja.html | 7 |
4 files changed, 42 insertions, 30 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 5a26ea79d9..370f5ecd50 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -224,14 +224,14 @@ GetVpValue(VALUE v, int must) #ifdef ENABLE_NUMERIC_STRING case T_STRING: SafeStringValue(v); - return VpCreateRbObject(strlen(RSTRING_PTR(v)) + VpBaseFig() + 1, - RSTRING_PTR(v)); + return VpCreateRbObject(strlen(RSTRING(v)->ptr) + VpBaseFig() + 1, + RSTRING(v)->ptr); #endif /* ENABLE_NUMERIC_STRING */ case T_BIGNUM: bg = rb_big2str(v, 10); - return VpCreateRbObject(strlen(RSTRING_PTR(bg)) + VpBaseFig() + 1, - RSTRING_PTR(bg)); + return VpCreateRbObject(strlen(RSTRING(bg)->ptr) + VpBaseFig() + 1, + RSTRING(bg)->ptr); default: goto SomeOneMayDoIt; } @@ -240,7 +240,7 @@ SomeOneMayDoIt: if(must) { rb_raise(rb_eTypeError, "%s can't be coerced into BigDecimal", rb_special_const_p(v)? - RSTRING_PTR(rb_inspect(v)): + RSTRING(rb_inspect(v))->ptr: rb_obj_classname(v) ); } @@ -332,7 +332,7 @@ BigDecimal_load(VALUE self, VALUE str) unsigned long m=0; SafeStringValue(str); - pch = RSTRING_PTR(str); + pch = RSTRING(str)->ptr; /* First get max prec */ while((*pch)!=(unsigned char)'\0' && (ch=*pch++)!=(unsigned char)':') { if(!ISDIGIT(ch)) { @@ -474,7 +474,7 @@ VpNewRbClass(U_LONG mx, char *str, VALUE klass) } VP_EXPORT Real * -VpCreateRbObject(U_LONG mx, const char *str) +VpCreateRbObject(U_LONG mx, char *str) { Real *pv = VpAlloc(mx,str); pv->obj = (VALUE)Data_Wrap_Struct(rb_cBigDecimal, 0, BigDecimal_delete, pv); @@ -781,6 +781,17 @@ BigDecimal_eq(VALUE self, VALUE r) return BigDecimalCmp(self, r, '='); } +/* Returns true if the values are not equal in value. Values may be coerced + * to perform the comparison: + * + * BigDecimal.new('1.0') != 1.0 -> false + */ +static VALUE +BigDecimal_ne(VALUE self, VALUE r) +{ + return BigDecimalCmp(self, r, '!'); +} + /* call-seq: * a < b * @@ -1265,7 +1276,7 @@ BigDecimal_round(int argc, VALUE *argv, VALUE self) { ENTER(5); Real *c, *a; - int iLoc = 0; + int iLoc; U_LONG mx; VALUE vLoc; VALUE vRound; @@ -1499,7 +1510,7 @@ BigDecimal_to_s(int argc, VALUE *argv, VALUE self) if(rb_scan_args(argc,argv,"01",&f)==1) { if(TYPE(f)==T_STRING) { SafeStringValue(f); - psz = RSTRING_PTR(f); + psz = RSTRING(f)->ptr; if(*psz==' ') { fPlus = 1; psz++; } else if(*psz=='+') { @@ -1676,7 +1687,7 @@ BigDecimal_global_new(int argc, VALUE *argv, VALUE self) mf = GetPositiveInt(nFig); } SafeStringValue(iniValue); - GUARD_OBJ(pv,VpCreateRbObject(mf, RSTRING_PTR(iniValue))); + GUARD_OBJ(pv,VpCreateRbObject(mf, RSTRING(iniValue)->ptr)); return ToValue(pv); } @@ -1707,7 +1718,7 @@ BigDecimal_new(int argc, VALUE *argv, VALUE self) mf = GetPositiveInt(nFig); } SafeStringValue(iniValue); - GUARD_OBJ(pv,VpNewRbClass(mf, RSTRING_PTR(iniValue),self)); + GUARD_OBJ(pv,VpNewRbClass(mf, RSTRING(iniValue)->ptr,self)); return ToValue(pv); } @@ -1928,6 +1939,7 @@ Init_bigdecimal(void) rb_define_method(rb_cBigDecimal, "==", BigDecimal_eq, 1); rb_define_method(rb_cBigDecimal, "===", BigDecimal_eq, 1); rb_define_method(rb_cBigDecimal, "eql?", BigDecimal_eq, 1); + rb_define_method(rb_cBigDecimal, "!=", BigDecimal_ne, 1); rb_define_method(rb_cBigDecimal, "<", BigDecimal_lt, 1); rb_define_method(rb_cBigDecimal, "<=", BigDecimal_le, 1); rb_define_method(rb_cBigDecimal, ">", BigDecimal_gt, 1); @@ -2175,7 +2187,7 @@ VpIsNegDoubleZero(double v) } VP_EXPORT int -VpException(unsigned short f, const char *str,int always) +VpException(unsigned short f,char *str,int always) { VALUE exc; int fatal=0; @@ -2317,7 +2329,7 @@ NaN: * returns number of chars needed to represent vp in specified format. */ VP_EXPORT U_LONG -VpNumOfChars(Real *vp,const char *pszFmt) +VpNumOfChars(Real *vp,char *pszFmt) { S_INT ex; U_LONG nc; @@ -2420,7 +2432,7 @@ VpInit(U_LONG BaseVal) } VP_EXPORT Real * -VpOne(void) +VpOne() { return VpConstOne; } @@ -2470,7 +2482,7 @@ overflow: * NULL be returned if memory allocation is failed,or any error. */ VP_EXPORT Real * -VpAlloc(U_LONG mx, const char *szVal) +VpAlloc(U_LONG mx, char *szVal) { U_LONG i, ni, ipn, ipf, nf, ipe, ne, nalloc; char v,*psz; @@ -3885,7 +3897,7 @@ VpToFString(Real *a,char *psz,int fFmt,int fPlus) * ne ... number of characters in exp_chr[],not including '+/-'. */ VP_EXPORT int -VpCtoV(Real *a, const char *int_chr, U_LONG ni, const char *frac, U_LONG nf, const char *exp_chr, U_LONG ne) +VpCtoV(Real *a, char *int_chr, U_LONG ni, char *frac, U_LONG nf, char *exp_chr, U_LONG ne) { U_LONG i, j, ind_a, ma, mi, me; U_LONG loc; diff --git a/ext/bigdecimal/bigdecimal.h b/ext/bigdecimal/bigdecimal.h index 4f77feab00..aabc551a76 100644 --- a/ext/bigdecimal/bigdecimal.h +++ b/ext/bigdecimal/bigdecimal.h @@ -105,7 +105,7 @@ typedef struct { VP_EXPORT Real * VpNewRbClass(U_LONG mx,char *str,VALUE klass); -VP_EXPORT Real *VpCreateRbObject(U_LONG mx,const char *str); +VP_EXPORT Real *VpCreateRbObject(U_LONG mx,char *str); VP_EXPORT U_LONG VpBaseFig(void); VP_EXPORT U_LONG VpDblFig(void); @@ -126,13 +126,13 @@ VP_EXPORT int VpIsRoundMode(unsigned long n); VP_EXPORT unsigned long VpGetRoundMode(void); VP_EXPORT unsigned long VpSetRoundMode(unsigned long n); -VP_EXPORT int VpException(unsigned short f,const char *str,int always); +VP_EXPORT int VpException(unsigned short f,char *str,int always); VP_EXPORT int VpIsNegDoubleZero(double v); -VP_EXPORT U_LONG VpNumOfChars(Real *vp,const char *pszFmt); +VP_EXPORT U_LONG VpNumOfChars(Real *vp,char *pszFmt); VP_EXPORT U_LONG VpInit(U_LONG BaseVal); VP_EXPORT void *VpMemAlloc(U_LONG mb); VP_EXPORT void VpFree(Real *pv); -VP_EXPORT Real *VpAlloc(U_LONG mx, const char *szVal); +VP_EXPORT Real *VpAlloc(U_LONG mx, char *szVal); VP_EXPORT int VpAsgn(Real *c,Real *a,int isw); VP_EXPORT int VpAddSub(Real *c,Real *a,Real *b,int operation); VP_EXPORT int VpMult(Real *c,Real *a,Real *b); @@ -143,7 +143,7 @@ VP_EXPORT void VpSzMantissa(Real *a,char *psz); VP_EXPORT int VpToSpecialString(Real *a,char *psz,int fPlus); VP_EXPORT void VpToString(Real *a,char *psz,int fFmt,int fPlus); VP_EXPORT void VpToFString(Real *a,char *psz,int fFmt,int fPlus); -VP_EXPORT int VpCtoV(Real *a,const char *int_chr,U_LONG ni,const char *frac,U_LONG nf,const char *exp_chr,U_LONG ne); +VP_EXPORT int VpCtoV(Real *a,char *int_chr,U_LONG ni,char *frac,U_LONG nf,char *exp_chr,U_LONG ne); VP_EXPORT int VpVtoD(double *d,S_LONG *e,Real *m); VP_EXPORT void VpDtoV(Real *m,double d); VP_EXPORT void VpItoV(Real *m,S_INT ival); @@ -155,7 +155,7 @@ VP_EXPORT void VpFrac(Real *y,Real *x); VP_EXPORT int VpPower(Real *y,Real *x,S_INT n); /* VP constants */ -VP_EXPORT Real *VpOne(void); +VP_EXPORT Real *VpOne(); /* * ------------------ diff --git a/ext/bigdecimal/bigdecimal_en.html b/ext/bigdecimal/bigdecimal_en.html index c2b86faef6..02c88df43e 100644 --- a/ext/bigdecimal/bigdecimal_en.html +++ b/ext/bigdecimal/bigdecimal_en.html @@ -379,7 +379,7 @@ after every n digits for readability. <CODE><PRE> BigDecimal("0.1234567890123456789").to_s(10) # ==> "0.1234567890 123456789E0" </PRE></CODE> -n can be a string representing a positive integer number. +n can be an string representing a positive integer number. <CODE><PRE> BigDecimal("0.1234567890123456789").to_s("10") # ==> "0.1234567890 123456789E0" </PRE></CODE> @@ -678,9 +678,10 @@ structure. </DL> <H3>Disadvantage of decimal representation</H3> -Because most computers have no internal decimal representaion. -Once you use BigDecimal,you need to keep using it without -considering computation cost if exact computation is required. +Advantages stated so far can also be disadvantages if the input from outside is + represented in binary. +Translation error from decimal to binary or vice versa is inevitable. +So,translation from Float(binary) to BigDecimal(decimal) is not alway done exactly. <H4>Which is the first input?</H4> Because most people uses decimal notatin for numeric data representation, diff --git a/ext/bigdecimal/bigdecimal_ja.html b/ext/bigdecimal/bigdecimal_ja.html index 37bbcbbb09..8fd95a6fe3 100644 --- a/ext/bigdecimal/bigdecimal_ja.html +++ b/ext/bigdecimal/bigdecimal_ja.html @@ -676,11 +676,10 @@ exponent=1、sign=2 なら数値が 1234.56784321 であるのは見れば直ぐに分かります。 <H3>10進のデメリット</H3> 実は今までのメリットは、そのままデメリットにもなります。 -そもそも、10進を2進に変換するような操作は変換誤差 +そもそも、10進を2進、2進を10進に変換するような操作は変換誤差 を伴う場合を回避することはできません。 -大概のコンピュータは10進の内部表現を持っていないので、 -BigDecimal を利用して誤差無しの計算をする場合は、計算速度 -を無視しても最後まで BigDecimal を使用続ける必要があります。 +既に計算機内部に取り込まれた2進数値を BigDecimal の内部表現に +変換するときには誤差が避けられない場合があります。 <H3>最初は何か?</H3> 自分で計算するときにわざわざ2進数を使う人は極めてまれです。 |