Anything

This blog describes anything about @mrkn's thoughts, which includes computer programming (mostly Ruby, Haskell, and C++), mathematics, physics, and so on. Each article is written in English for learning it.

2011-08-23

Instantiation a literal of decimal fraction without its exponent part as a Rational

In Ruby, a literal of decimal fraction is instantiated as a Float.

I make a patch to modify it so that a literal of decimal fraction without its exponent part is instantiated as a Rational.

The reason why I wrote this patch is that I think most Rubyists don't need to use Float values. Correct use of Float values is difficult for many people, especially most of Rubyists, who aren't well acquainted with floating-point number arithmetic. I want to realize the world that nobody is in trouble with floating-point errors.

I will talk about such a topic in RubyConf 2011. The talk is titled "Float is Legacy". I've got this title from Ujihisa. I love this title.

2011-04-14

My original color scheme for vim "mrkn256.vim" is available on github

I have my original color scheme for vim, called "mrkn256.vim". It has been available on a page in vim.org.

Today, I have created a git repository for mrkn256.vim and a project in github for it , and pushed it into the project. So mrkn256.vim color scheme is also available on github.

Enjoy hacking with vim!

2010-09-06

We can get faster fib just returning two values

How do you make fib fast?
I don't recomend using memoization because it require waste memory.
I recommend returning two values.

RSpec and Cucumber

I'm reading The RSpec Book.

I've understand:
  • RSpec should be used to describe the behavior of objects.
  • For describing the behavior of a library, Cucumber should be used.

2010-08-14

Free online textbooks for computer arithmetic

I'm the maintainer of the bigdecimal library of CRuby.  Recently, I'm studying computer arithmetic so improving the performance of the bigdecimal.  My favorite text is TAOCP vol. 2.

Today, I found two free online textbooks for computer arithmetic.  Although I've read just their preface parts, I'm believing it is bliss that they are available as free media.

2009-12-18

To use preprocessor macros on gdb

When debugging ruby on gdb, we often want to expand some preprocessor macros, such as RSTRING_LEN, RARRAY_PTR. To make preprocessor macros available to gdb, we should call gcc with these debugging options: -gdwarf-2 -g3.

To configure ruby with these options, we do,

./configure debugflags="-gdwarf-2 -g3"

Then build ruby,

make

This allows us to expand preprocessor macros in gdb like this:

$ gdb --quiet /opt/ruby/trunk/bin/ruby
Reading symbols for shared libraries .... done
(gdb) b ruby_yyparse 
Breakpoint 1 at 0x20c49ba5cd1c8b: file parse.c, line 4583.
(gdb) r
Starting program: /opt/ruby/trunk/bin/ruby 
Reading symbols for shared libraries +++... done
Reading symbols for shared libraries . done

Breakpoint 1, ruby_yyparse (parser=0x10060c310) at parse.c:4583
4583    {
(gdb) macro expand Qfalse
expands to: ((VALUE)RUBY_Qfalse)
(gdb) info macro RSTRING_PTR
Defined at ../include/ruby/ruby.h:619
  included at /Users/muraken/src/ruby.git/build-osx/parse.c:18
#define RSTRING_PTR(str) (!(RBASIC(str)->flags & RSTRING_NOEMBED) ? RSTRING(str)->as.ary : RSTRING(str)->as.heap.ptr)
(gdb) 

Note that we must be in a frame where the target preprocessor macros are visible.

I thank hayeah and ujihisa for helpful discussion about this topic and proofreading my English.

See also:

Followers