Project

overflow

0.0
No commit activity in last 3 years
No release in over 3 years
Overflow is a class to overflow calculated as C language in Ruby.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 0
~> 2.11
 Project Readme

Overflow

Gem Version Build Status

Overflow is a class to overflow calculated as C language in Ruby.

Usage

require 'overflow'

over = Overflow.new "C" #=> "C" mean 8bit unsigned char (same as pack template)
over.set 255 #=> set a number (0b11111111)
p over.to_i #=> 255 (out Fixnum object)
over = over << 4 #=> left bit shift (0b11110000)
p over.to_i #=> 240 (overflow bit is dropped)
p (over >> 4).to_i #=> 15 (0b00001111)
p (200 - over) #=> -40 (Call Overflow#coerce.)

APIs

initialize(type[, number])

type: defined C type

All type mean same that pack template.

  • c: int8_t
  • C: uint8_t
  • s: int16_t
  • S: uint16_t
  • i: int
  • I: unsigned int
  • l: int32_t
  • L: uint32_t
  • q: int64_t
  • Q: uint64_t

set(number)

over = Overflow.new "C"
over.set 1
p over.to_i #=> 1
over.set 10
p over.to_i #=> 10

to_i

over = Overflow.new "C", 256
over.to_i #=> 0

+, -, *

over = Overflow.new "C", 100
over += 200 #=> 44
over -= 50  #=> 250
over *= 10  #=> 196

~, &, |, ^

over = Overflow.new "C", 0xaa
~over #=> 0x55
over & 0x99 #=> 0x88
over | 0x99 #=> 0xbb
over ^ 0x99 #=> 0x33

<<, >>

over = Overflow.new "C", 0xff
over << 4 #=> 0xf0
over >> 4 #=> 0x0f

and all Numeric methods.

Class tree

Overflow < Numeric

Installation

Add this line to your application's Gemfile:

gem 'overflow'

And then execute:

$ bundle

Or install it yourself as:

$ gem install overflow

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

See the file LICENSE.txt