Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix floor, ceil, round and associated tests
  • Loading branch information
Whiteknight committed Nov 15, 2009
1 parent e7e880d commit 1d2a274
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
14 changes: 10 additions & 4 deletions src/builtins/ceil.pir
Expand Up @@ -4,14 +4,20 @@
.param int nargout
.param int nargin
.param pmc matrix
.const "Sub" helper = "!_ceil_helper"
.const "Sub" helper = "!__ceil_helper"

$P0 = clone matrix
$P0.'iterate_function_inplace'(helper)
$I0 = '!is_scalar'(matrix)
if $I0 == 0 goto is_a_matrix
$N0 = matrix
$N1 = ceil $N0
.return($N1)

is_a_matrix:
$P0 = matrix.'iterate_function_external'(helper)
.return($P0)
.end

.sub '!_ceil_helper'
.sub '!__ceil_helper'
.param pmc matrix
.param num value
.param int x
Expand Down
10 changes: 8 additions & 2 deletions src/builtins/floor.pir
Expand Up @@ -4,13 +4,19 @@
.param int nargout
.param int nargin
.param pmc matrix
.const "Sub" helper = "!_floor_helper"
.const "Sub" helper = "!__floor_helper"

$I0 = '!is_scalar'(matrix)
if $I0 == 0 goto is_a_matrix
$N0 = matrix
$N1 = floor $N0
.return($N1)
is_a_matrix:
$P0 = matrix.'iterate_function_external'(helper)
.return($P0)
.end

.sub '!_floor_helper' :anon
.sub '!__floor_helper' :anon
.param pmc matrix
.param num value
.param int x
Expand Down
23 changes: 12 additions & 11 deletions src/builtins/round.pir
Expand Up @@ -4,25 +4,26 @@
.param int nargout
.param int nargin
.param pmc matrix
.const "Sub" helper = "__round_helper"
.const "Sub" helper = "!__round_helper"

$S0 = typeof matrix
if $S0 == 'NumMatrix2D' goto _have_matrix
.return(matrix)
$I0 = '!is_scalar'(matrix)
if $I0 == 0 goto is_a_matrix
$N0 = matrix
$N0 = $N0 + 0.5
$N1 = floor $N0
.return($N1)

_have_matrix:
.local pmc new_matrix
new_matrix = clone matrix
new_matrix.'iterate_function_inplace'(helper)
is_a_matrix:
$P0 = matrix.'iterate_function_external'(helper)
.return($P0)
.end

.sub '__round_helper' :anon
.sub '!__round_helper' :anon
.param pmc matrix
.param num value
.param int x
.param int y
$N0 = value
$N1 = $N0 + 0.5
$N1 = value + 0.5
$I0 = floor $N1
$N2 = $I0
.return($N2)
Expand Down

0 comments on commit 1d2a274

Please sign in to comment.