about summary refs log blame commit diff stats
path: root/tutorial/task10-hint1.mu
blob: 903284f4bc89d004ad94d0bac87614764b4443bb (plain) (tree)

























































                                                                                                                   
fn to-km miles: float -> _/xmm1: float {
  var result/xmm1: float <- copy miles
  # fill in the blanks to compute miles * 1.609
  # 1.609 = 1609 / 1000 (use function `rational`)

  return result
}

fn test-to-km {
  # 0 miles = 0 km
  var zero: float  # Mu implicitly initializes variables in memory to 0
  var result/xmm1: float <- to-km zero
  compare result, zero
  {
    break-if-=
    draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "F - 0 miles = 0 km\n", 3/fg 0/bg
    count-test-failure
  }
  # 1 mile = 1.609 km approximately
  var one/eax: int <- copy 1
  var one-float/xmm0: float <- convert one
  result <- to-km one-float
  var lower-bound/xmm0: float <- rational 0x649, 0x3e8  # 1609/1000 in hex
  {
    compare result, lower-bound
    break-if-float>=
    draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "F - 1 mile > 1.609 km\n", 3/fg 0/bg
    count-test-failure
  }
  var upper-bound/xmm0: float <- rational 0x64a, 0x3e8  # 1610/1000 in hex
  {
    compare result, upper-bound
    break-if-float<=
    draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "F - 1 mile < 1.610 km\n", 3/fg 0/bg
    count-test-failure
  }
  # 2 miles = 3.218 km approximately
  var two/eax: int <- copy 2
  var two-float/xmm0: float <- convert two
  result <- to-km two-float
  var lower-bound/xmm0: float <- rational 0xc92, 0x3e8  # 3218/1000 in hex
  {
    compare result, lower-bound
    break-if-float>=
    draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "F - 2 miles > 3.218 km\n", 3/fg 0/bg
    count-test-failure
  }
  var upper-bound/xmm0: float <- rational 0xc93, 0x3e8  # 3219/1000 in hex
  {
    compare result, upper-bound
    break-if-float<=
    draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "F - 2 miles < 3.219 km\n", 3/fg 0/bg
    count-test-failure
  }
}

fn main {
}
an> * Profanity is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Profanity is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Profanity. If not, see <https://www.gnu.org/licenses/>. * * In addition, as a special exception, the copyright holders give permission to * link the code of portions of this program with the OpenSSL library under * certain conditions as described in each individual source file, and * distribute linked combinations including the two. * * You must obey the GNU General Public License in all respects for all of the * code used other than OpenSSL. If you modify file(s) with this exception, you * may extend this exception to your version of the file(s), but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. If you delete this exception statement from all * source files in the program, then also delete it here. * */ #ifndef XMPP_ROSTER_LIST_H #define XMPP_ROSTER_LIST_H #include <glib.h> #include "xmpp/resource.h" #include "xmpp/contact.h" typedef enum { ROSTER_ORD_NAME, ROSTER_ORD_PRESENCE } roster_ord_t; void roster_clear(void); gboolean roster_update_presence(const char *const barejid, Resource *resource, GDateTime *last_activity); PContact roster_get_contact(const char *const barejid); gboolean roster_contact_offline(const char *const barejid, const char *const resource, const char *const status); void roster_reset_search_attempts(void); void roster_create(void); void roster_destroy(void); void roster_change_name(PContact contact, const char *const new_name); void roster_remove(const char *const name, const char *const barejid); void roster_update(const char *const barejid, const char *const name, GSList *groups, const char *const subscription, gboolean pending_out); gboolean roster_add(const char *const barejid, const char *const name, GSList *groups, const char *const subscription, gboolean pending_out); char* roster_barejid_from_name(const char *const name); GSList* roster_get_contacts(roster_ord_t order); GSList* roster_get_contacts_online(void); gboolean roster_has_pending_subscriptions(void); char* roster_contact_autocomplete(const char *const search_str); char* roster_fulljid_autocomplete(const char *const search_str); GSList* roster_get_group(const char *const group, roster_ord_t order); GSList* roster_get_groups(void); char* roster_group_autocomplete(const char *const search_str); char* roster_barejid_autocomplete(const char *const search_str); GSList* roster_get_contacts_by_presence(const char *const presence); char* roster_get_msg_display_name(const char *const barejid, const char *const resource); #endif