Task

Determine whether a given year is a leap year in the Gregorian calendar.



See also

 Leap year (wiki)


(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)
    (i32.and
      (i32.eqz (i32.rem_u (get_local $year) (i32.const 4)))  ;; year%4 == 0
      (i32.or
        (i32.ne (i32.rem_u (get_local $year) (i32.const 100)) (i32.const 0))   ;; year%100 != 0
        (i32.eqz (i32.rem_u (get_local $year) (i32.const 400)))  ;; yaer%400 == 0
      )
    )
  )
  (export "isLeapYear" (func $isLeapYear))
)