Package org.jruby

Examples of org.jruby.RubyBignum


       }

       public static String convertToLong(Object rubyObject) throws AxisFault {
           try {
                if(rubyObject instanceof RubyInteger){
               RubyBignum longObject = (RubyBignum) rubyObject;
               return longObject.toString();
               }
                return Long.toString(RubyBignum.num2long((IRubyObject)rubyObject)) ;
               //return rubyObject.toString();
           } catch (Exception e) {
               throw new AxisFault("Unable to convert the return value to long");
View Full Code Here


                        occurrences = encode.remaining();
                    }

                    long ul = 0;
                    long ulmask = (0xfe << 56) & 0xffffffff;
                    RubyBignum big128 = RubyBignum.newBignum(runtime, 128);
                    int pos = encode.position();

                    while (occurrences > 0 && pos < encode.limit()) {
                        ul <<= 7;
                        ul |= encode.get(pos) & 0x7f;
                        if((encode.get(pos++) & 0x80) == 0) {
                            result.append(RubyFixnum.newFixnum(runtime, ul));
                            occurrences--;
                            ul = 0;
                        } else if((ul & ulmask) == 0) {
                            RubyBignum big = RubyBignum.newBignum(runtime, ul);
                            while(occurrences > 0 && pos < encode.limit()) {
                                big = (RubyBignum)big.op_mul(runtime.getCurrentContext(), big128);
                                IRubyObject v = big.op_plus(runtime.getCurrentContext(),
                                        RubyBignum.newBignum(runtime, encode.get(pos) & 0x7f));
                                if(v instanceof RubyFixnum) {
                                    big = RubyBignum.newBignum(runtime, RubyNumeric.fix2long(v));
                                } else if (v instanceof RubyBignum) {
                                    big = (RubyBignum)v;
View Full Code Here

                            throw runtime.newTypeError("pack('w') does not take nil");
                        }


                        if(from instanceof RubyBignum) {
                            RubyBignum big128 = RubyBignum.newBignum(runtime, 128);
                            while (from instanceof RubyBignum) {
                                RubyBignum bignum = (RubyBignum)from;
                                RubyArray ary = (RubyArray)bignum.divmod(runtime.getCurrentContext(), big128);
                                buf.append((byte)(RubyNumeric.fix2int(ary.at(RubyFixnum.one(runtime))) | 0x80) & 0xff);
                                from = ary.at(RubyFixnum.zero(runtime));
                            }
                        }
View Full Code Here

                        occurrences = encode.remaining();
                    }

                    long ul = 0;
                    long ulmask = (0xfe << 56) & 0xffffffff;
                    RubyBignum big128 = RubyBignum.newBignum(runtime, 128);
                    int pos = encode.position();

                    while (occurrences > 0 && pos < encode.limit()) {
                        ul <<= 7;
                        ul |= encode.get(pos) & 0x7f;
                        if((encode.get(pos++) & 0x80) == 0) {
                            result.append(RubyFixnum.newFixnum(runtime, ul));
                            occurrences--;
                            ul = 0;
                        } else if((ul & ulmask) == 0) {
                            RubyBignum big = RubyBignum.newBignum(runtime, ul);
                            while(occurrences > 0 && pos < encode.limit()) {
                                big = (RubyBignum)big.op_mul(runtime.getCurrentContext(), big128);
                                IRubyObject v = big.op_plus(runtime.getCurrentContext(),
                                        RubyBignum.newBignum(runtime, encode.get(pos) & 0x7f));
                                if(v instanceof RubyFixnum) {
                                    big = RubyBignum.newBignum(runtime, RubyNumeric.fix2long(v));
                                } else if (v instanceof RubyBignum) {
                                    big = (RubyBignum)v;
View Full Code Here

                        if (from.isNil()) throw runtime.newTypeError("pack('w') does not take nil");


                        if (from instanceof RubyBignum) {
                            RubyBignum big128 = RubyBignum.newBignum(runtime, 128);
                            while (from instanceof RubyBignum) {
                                RubyBignum bignum = (RubyBignum)from;
                                RubyArray ary = (RubyArray)bignum.divmod(runtime.getCurrentContext(), big128);
                                buf.append((byte)(RubyNumeric.fix2int(ary.at(RubyFixnum.one(runtime))) | 0x80) & 0xff);
                                from = ary.at(RubyFixnum.zero(runtime));
                            }
                        }
View Full Code Here

                        occurrences = encode.remaining();
                    }

                    long ul = 0;
                    long ulmask = (0xfe << 56) & 0xffffffff;
                    RubyBignum big128 = RubyBignum.newBignum(runtime, 128);
                    int pos = encode.position();

                    while (occurrences > 0 && pos < encode.limit()) {
                        ul <<= 7;
                        ul |= encode.get(pos) & 0x7f;
                        if((encode.get(pos++) & 0x80) == 0) {
                            result.append(RubyFixnum.newFixnum(runtime, ul));
                            occurrences--;
                            ul = 0;
                        } else if((ul & ulmask) == 0) {
                            RubyBignum big = RubyBignum.newBignum(runtime, ul);
                            while(occurrences > 0 && pos < encode.limit()) {
                                IRubyObject mulResult = big.op_mul(runtime.getCurrentContext(), big128);
                                IRubyObject v = mulResult.callMethod(runtime.getCurrentContext(), "+",
                                        RubyBignum.newBignum(runtime, encode.get(pos) & 0x7f));
                                if(v instanceof RubyFixnum) {
                                    big = RubyBignum.newBignum(runtime, RubyNumeric.fix2long(v));
                                } else if (v instanceof RubyBignum) {
                                    big = (RubyBignum)v;
                                }
                                if((encode.get(pos++) & 0x80) == 0) {
                                    result.add(RubyBignum.bignorm(runtime, big.getValue()));
                                    occurrences--;
                                    ul = 0;
                                    break;
                                }
                            }
View Full Code Here

                        if (from.isNil()) throw runtime.newTypeError("pack('w') does not take nil");


                        if (from instanceof RubyBignum) {
                            RubyBignum big128 = RubyBignum.newBignum(runtime, 128);
                            while (from instanceof RubyBignum) {
                                RubyBignum bignum = (RubyBignum)from;
                                RubyArray ary = (RubyArray)bignum.divmod(runtime.getCurrentContext(), big128);
                                buf.append((byte)(RubyNumeric.fix2int(ary.at(RubyFixnum.one(runtime))) | 0x80) & 0xff);
                                from = ary.at(RubyFixnum.zero(runtime));
                            }
                        }
View Full Code Here

TOP

Related Classes of org.jruby.RubyBignum

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.