Skip to content

Commit

Permalink
- Fixed a critical bug in the Math pacakge -- the Math::BigFloat is n…
Browse files Browse the repository at this point in the history
…ow initialized on Math.new, otherwise the program freezes when calling a method such as Math.pi and Math::BigFloat is not initialized.
  • Loading branch information
trizen committed Sep 10, 2015
1 parent 6dae437 commit 9ee37d0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ scripts/Rosettacode/Terminal_control_Unicode_output.sf
scripts/Rosettacode/Tokenize_a_string.sf
scripts/Rosettacode/Topic_variable.sf
scripts/Rosettacode/Tree_traversal.sf
scripts/Rosettacode/Trigonometric_functions.sf
scripts/Rosettacode/Unicode_strings.sf
scripts/Rosettacode/Unicode_variable_names.sf
scripts/Rosettacode/Universal_Turing_machine.sf
Expand Down
5 changes: 4 additions & 1 deletion lib/Sidef/Math/Math.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ package Sidef::Math::Math {
our @ISA = qw(Sidef);

sub new {
state $x = require Math::BigFloat;
state $x = do {
require Math::BigFloat;
Math::BigFloat->new;
};
bless {}, __PACKAGE__;
}

Expand Down
26 changes: 26 additions & 0 deletions scripts/Rosettacode/Trigonometric_functions.sf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/ruby

#
## http://rosettacode.org/wiki/Trigonometric_functions
#

var angle_deg = 45;
var angle_rad = Math.pi/4;

[
[Math.sin(angle_rad), Math.sin(Math.deg2rad(angle_deg))],
[Math.cos(angle_rad), Math.cos(Math.deg2rad(angle_deg))],
[Math.tan(angle_rad), Math.tan(Math.deg2rad(angle_deg))],
[Math.cot(angle_rad), Math.cot(Math.deg2rad(angle_deg))],
].each { |arr|
say arr.join(" ");
}

[
Math.asin(Math.sin(angle_rad)),
Math.acos(Math.cos(angle_rad)),
Math.atan(Math.tan(angle_rad)),
Math.acot(Math.cot(angle_rad)),
].each { |n|
say [n, Math.rad2deg(n)].join(" ");
}

0 comments on commit 9ee37d0

Please sign in to comment.