22 lines
571 B
Text
22 lines
571 B
Text
(module
|
|
;; function isLeapYear: returns 1 if its argument (e.g. 2004) is a leap year, 0 otherwise.
|
|
;; Returns year%4==0 and (year%100!=0 or year%400==0)
|
|
(func $isLeapYear (param $year i32) (result i32)
|
|
get_local $year
|
|
i32.const 4
|
|
i32.rem_u
|
|
i32.eqz ;; year % 4 == 0
|
|
get_local $year
|
|
i32.const 100
|
|
i32.rem_u
|
|
i32.const 0
|
|
i32.ne ;; year % 100 != 0
|
|
get_local $year
|
|
i32.const 400
|
|
i32.rem_u
|
|
i32.eqz ;; year % 400 == 0
|
|
i32.or
|
|
i32.and
|
|
)
|
|
(export "isLeapYear" (func $isLeapYear))
|
|
)
|