fraction 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/fraction.c +14 -3
  2. metadata +22 -39
data/fraction.c CHANGED
@@ -134,12 +134,23 @@ VALUE method_whole_fraction_for(int argc, VALUE * argv, VALUE self)
134
134
  rb_scan_args(argc, argv, "01", &maxdenr);
135
135
  if (!NIL_P(maxdenr))
136
136
  maxden = NUM2INT(maxdenr);
137
- double x = NUM2DBL(self);
137
+
138
+ if (rb_equal(INT2FIX(0), self)){
139
+ rb_ary_store(res, 0, INT2FIX(0));
140
+ rb_ary_store(res, 1, INT2FIX(0));
141
+ rb_ary_store(res, 2, INT2FIX(1));
142
+ rb_ary_store(res, 3, INT2FIX(0));
143
+ return res;
144
+ }
145
+
146
+ VALUE wholen = rb_funcall(self, rb_intern("truncate"), 0);
147
+ VALUE subval = rb_funcall(rb_funcall(self, rb_intern("-"), 1, wholen), rb_intern("abs"), 0);
148
+
149
+ double x = NUM2DBL(subval);
138
150
  long n, d;
139
151
  double e;
140
152
  core_fraction(x, maxden, &n, &d, &e);
141
- VALUE wholen = INT2NUM(n / d);
142
- VALUE numer1 = INT2NUM(n % d);
153
+ VALUE numer1 = INT2NUM(n);
143
154
  VALUE denom1 = INT2NUM(d);
144
155
  VALUE err1 = rb_float_new(e);
145
156
 
metadata CHANGED
@@ -1,68 +1,51 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: fraction
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 3
8
- - 1
9
- version: 0.3.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.2
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Christopher Lord
13
9
  - David Eppstein
14
10
  - Arno Formella
15
11
  autorequire:
16
12
  bindir: bin
17
13
  cert_chain: []
18
-
19
- date: 2011-05-30 00:00:00 -04:00
20
- default_executable:
14
+ date: 2011-12-02 00:00:00.000000000Z
21
15
  dependencies: []
22
-
23
- description: Provides "to_fraction" and to_whole_fraction methods on all ruby floats and numerics.
16
+ description: Provides "to_fraction" and to_whole_fraction methods on all ruby floats
17
+ and numerics.
24
18
  email: christopherlord+fractiongem@gmail.com
25
19
  executables: []
26
-
27
- extensions:
20
+ extensions:
28
21
  - extconf.rb
29
22
  extra_rdoc_files: []
30
-
31
- files:
23
+ files:
32
24
  - fraction.c
33
25
  - README.md
34
26
  - extconf.rb
35
- has_rdoc: true
36
27
  homepage: https://github.com/clord/fraction
37
28
  licenses: []
38
-
39
29
  post_install_message:
40
30
  rdoc_options: []
41
-
42
- require_paths:
31
+ require_paths:
43
32
  - lib
44
- required_ruby_version: !ruby/object:Gem::Requirement
33
+ required_ruby_version: !ruby/object:Gem::Requirement
45
34
  none: false
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- segments:
50
- - 0
51
- version: "0"
52
- required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
40
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- segments:
58
- - 0
59
- version: "0"
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
60
45
  requirements: []
61
-
62
46
  rubyforge_project:
63
- rubygems_version: 1.3.7
47
+ rubygems_version: 1.8.6
64
48
  signing_key:
65
49
  specification_version: 3
66
50
  summary: Provides a "to_fraction" method on all ruby floats.
67
51
  test_files: []
68
-