Tabnine Logo
RubyBignum.newBignum
Code IndexAdd Tabnine to your IDE (free)

How to use
newBignum
method
in
org.jruby.RubyBignum

Best Java code snippets using org.jruby.RubyBignum.newBignum (Showing top 20 results out of 315)

origin: bazelbuild/bazel

public static long num2ulong(Ruby runtime, IRubyObject value) {
  if (value instanceof RubyFloat) {
    RubyBignum bignum = RubyBignum.newBignum(runtime, ((RubyFloat) value).getDoubleValue());
    return RubyBignum.big2ulong(bignum);
  } else if (value instanceof RubyBignum) {
    return RubyBignum.big2ulong((RubyBignum) value);
  } else {
    return RubyNumeric.num2long(value);
  }
}
origin: bazelbuild/bazel

  long ret = (Long) value;
  return ret >= 0 ? runtime.newFixnum(ret) :
      RubyBignum.newBignum(runtime, UINT64_COMPLEMENTARY.add(new BigInteger(ret + "")));
case FLOAT:
  return runtime.newFloat((Float) value);
origin: org.jruby/jruby-complete

/** rb_big_abs
 *
 */
@Override
public IRubyObject abs(ThreadContext context) {
  return RubyBignum.newBignum(context.runtime, value.abs());
}
origin: org.jruby/jruby-complete

public static IRubyObject newUnsigned64(Ruby runtime, long value) {
  return value < 0
      ? RubyBignum.newBignum(runtime, BigInteger.valueOf(value & 0x7fffffffffffffffL).add(UINT64_BASE))
      : RubyFixnum.newFixnum(runtime, value);
}
origin: org.jruby/jruby-complete

/** rb_big_norm
 *
 */
public static RubyInteger bignorm(Ruby runtime, BigInteger bi) {
  return (bi.compareTo(LONG_MIN) < 0 || bi.compareTo(LONG_MAX) > 0) ?
        newBignum(runtime, bi) : runtime.newFixnum(bi.longValue());
}
origin: org.jruby/jruby-complete

private static RubyInteger toInteger(final Ruby runtime, final BigDecimal result) {
  if (result.compareTo(MAX_FIX) <= 0 && result.compareTo(MIN_FIX) >= 0) {
    return RubyFixnum.newFixnum(runtime, result.longValue());
  }
  return RubyBignum.newBignum(runtime, result.toBigInteger());
}
origin: org.jruby/jruby-complete

private static RubyInteger toRubyInteger(final Ruby runtime, final Number i) {
  if (i instanceof BigInteger) {
    return RubyBignum.newBignum(runtime, (BigInteger) i);
  }
  return RubyFixnum.newFixnum(runtime, i.longValue());
}
origin: org.jruby/jruby-complete

public IRubyObject convert(Ruby runtime, Object object) {
  if (object == null) return runtime.getNil();
  return RubyBignum.newBignum(runtime, (BigInteger)object);
}
public IRubyObject get(Ruby runtime, Object array, int i) {
origin: org.jruby/jruby-core

private static RubyInteger negate(final Ruby runtime, final long value) {
  if (value == MIN) { // a gotcha
    return RubyBignum.newBignum(runtime, BigInteger.valueOf(value).negate());
  }
  return RubyFixnum.newFixnum(runtime, -value);
}
origin: org.jruby/jruby-core

public static IRubyObject newUnsigned64(Ruby runtime, long value) {
  return value < 0
      ? RubyBignum.newBignum(runtime, BigInteger.valueOf(value & 0x7fffffffffffffffL).add(UINT64_BASE))
      : RubyFixnum.newFixnum(runtime, value);
}
origin: org.jruby/jruby-complete

private static RubyInteger negate(final Ruby runtime, final long value) {
  if (value == MIN) { // a gotcha
    return RubyBignum.newBignum(runtime, BigInteger.valueOf(value).negate());
  }
  return RubyFixnum.newFixnum(runtime, -value);
}
origin: com.ning.billing/killbill-osgi-bundles-jruby

public static IRubyObject newUnsigned64(ThreadContext context, long value) {
  return value < 0
      ? RubyBignum.newBignum(context.runtime, BigInteger.valueOf(value & 0x7fffffffffffffffL).add(UINT64_BASE))
      : RubyFixnum.newFixnum(context.runtime, value);
}
origin: org.jruby/jruby-complete

private static RubyBignum randomBignum(final ThreadContext context, final Number lower, final BigInteger upperExc) {
  BigInteger lowerBig = lower instanceof BigInteger ? (BigInteger) lower : BigInteger.valueOf(lower.longValue());
  BigInteger bound = upperExc.subtract(lowerBig);
  BigInteger rnd = nextBigInteger(getSecureRandom(context), bound, bound.bitLength());
  return RubyBignum.newBignum(context.runtime, rnd.add(lowerBig));
}
origin: org.jruby/jruby-complete

@JRubyMethod
public IRubyObject ceil(ThreadContext context) {
  checkFloatDomain();
  BigInteger ceil = value.setScale(0, RoundingMode.CEILING).toBigInteger();
  if (ceil.compareTo(BigInteger.valueOf((long) ceil.intValue())) == 0) { // It fits in Fixnum
    return RubyInteger.int2fix(context.runtime, ceil.intValue());
  }
  return RubyBignum.newBignum(context.runtime, ceil);
}
origin: org.jruby/jruby-complete

@JRubyMethod(name = "to_r")
public IRubyObject to_r(ThreadContext context) {
  checkFloatDomain();
  int scale = value.scale();
  BigInteger numerator = value.scaleByPowerOfTen(scale).toBigInteger();
  BigInteger denominator = BigInteger.TEN.pow(scale);
  return RubyRational.newInstance(context, RubyBignum.newBignum(context.runtime, numerator), RubyBignum.newBignum(context.runtime, denominator));
}
origin: org.jruby/jruby-complete

@Override
public IRubyObject op_mul(ThreadContext context, long otherValue) {
  Ruby runtime = context.runtime;
  try {
    return newFixnum(runtime, Math.multiplyExact(value, otherValue));
  } catch (ArithmeticException ae) {
    return RubyBignum.newBignum(runtime, value).op_mul(context, otherValue);
  }
}
origin: com.ning.billing/killbill-osgi-bundles-jruby

/** rb_big_neg
 *
 */
@JRubyMethod(name = "~")
public IRubyObject op_neg() {
  return RubyBignum.newBignum(getRuntime(), value.not());
}
origin: org.jruby/jruby-complete

private IRubyObject subtractOther(ThreadContext context, IRubyObject other) {
  if (other instanceof RubyBignum) {
    return RubyBignum.newBignum(context.runtime, value).op_minus(context, ((RubyBignum) other).value);
  }
  if (other instanceof RubyFloat) {
    return context.runtime.newFloat((double) value - ((RubyFloat) other).getDoubleValue());
  }
  return coerceBin(context, sites(context).op_minus, other);
}
origin: org.jruby/jruby-complete

public static RubyInteger f_gcd(ThreadContext context, RubyInteger x, RubyInteger y) {
  if (x instanceof RubyFixnum && y instanceof RubyFixnum && isLongMinValue((RubyFixnum) x))
    return RubyFixnum.newFixnum(context.runtime, i_gcd(x.getLongValue(), y.getLongValue()));
  BigInteger gcd = x.getBigIntegerValue().gcd(y.getBigIntegerValue());
  if (gcd.compareTo(RubyBignum.LONG_MAX) <= 0) { // gcd always positive
    return RubyFixnum.newFixnum(context.runtime, gcd.longValue());
  }
  return RubyBignum.newBignum(context.runtime, gcd);
}
origin: com.ning.billing/killbill-osgi-bundles-jruby

private IRubyObject lshift(long width) {
  if (width > BIT_SIZE - 1 || ((~0L << BIT_SIZE - width - 1) & value) != 0) {
    return RubyBignum.newBignum(getRuntime(), value).op_lshift(RubyFixnum.newFixnum(getRuntime(), width));
  }
  return RubyFixnum.newFixnum(getRuntime(), value << width);
}
org.jrubyRubyBignumnewBignum

Javadoc

Return a Bignum for the given value, or raise FloatDomainError if it is out of range. Note this method may return Bignum that are in Fixnum range.

Popular methods of RubyBignum

  • getLongValue
  • getValue
    Getter for property value.
  • <init>
  • addFloat
  • addOther
  • big2dbl
    rb_big2dbl
  • big2long
    rb_big2long
  • bignorm
    rb_big_norm
  • checkShiftDown
  • coerceBin
  • coerceCmp
  • compareTo
  • coerceCmp,
  • compareTo,
  • convertToDouble,
  • createBignumClass,
  • dbl_cmp,
  • divmod,
  • even_p,
  • fix2big,
  • getBigIntegerValue

Popular in Java

  • Making http requests using okhttp
  • getApplicationContext (Context)
  • setScale (BigDecimal)
  • getContentResolver (Context)
  • URI (java.net)
    A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by RFC
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • ArrayList (java.util)
    ArrayList is an implementation of List, backed by an array. All optional operations including adding
  • Dictionary (java.util)
    Note: Do not use this class since it is obsolete. Please use the Map interface for new implementatio
  • Hashtable (java.util)
    A plug-in replacement for JDK1.5 java.util.Hashtable. This version is based on org.cliffc.high_scale
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now