Fuzion Logo
fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

units/byte_iec.fz


# This file is part of the Fuzion language implementation.
#
# The Fuzion language implementation 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, version 3 of the License.
#
# The Fuzion language implementation 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 The
# Fuzion language implementation.  If not, see <https://www.gnu.org/licenses/>.


# -----------------------------------------------------------------------
#
#  Tokiwa Software GmbH, Germany
#
#  Source code of Fuzion standard library feature units.byte_iec
#
# -----------------------------------------------------------------------

# units.byte_iec -- unit type defining units used for units.data_size
#
# Uses base 2 prefixes defined by the International Electrotechnical Commission (IEC),
# e.g. 1024 Byte = 1 kibibyte.
#
public byte_iec(
            # the next smaller unit, like kibibyte is smaller than mebibyte, if it exists
            public smaller Lazy (option byte_iec),

            # the next larger unit, like gibibyte is larger than mebibyte, if it exists
            public larger  Lazy (option byte_iec),

            # the number of bytes in one of this unit
            public in_bytes u128,

            # a short name of at most three codepoints
            public short_name String,

            # a longer, but still short name of this unit
            public name String) is

  # byte unit
  #
  public type.b   units.byte_iec => units.byte_iec nil kib 1.as_u128            "B"   "byte"

  # kibibyte unit
  #
  public type.kib units.byte_iec => units.byte_iec b   mib 2.as_u128**10.as_u128  "KiB" "kibibyte"

  # mebibyte unit
  #
  public type.mib units.byte_iec => units.byte_iec kib gib 2.as_u128**20.as_u128  "MiB" "mebibyte"

  # gibibyte unit
  #
  public type.gib units.byte_iec => units.byte_iec mib tib 2.as_u128**30.as_u128  "GiB" "gibibyte"

  # tebibyte unit
  #
  public type.tib units.byte_iec => units.byte_iec gib pib 2.as_u128**40.as_u128  "TiB" "tebibyte"

  # pebibyte unit
  #
  public type.pib units.byte_iec => units.byte_iec tib eib 2.as_u128**50.as_u128  "PiB" "pebibyte"

  # exbibyte unit
  #
  public type.eib units.byte_iec => units.byte_iec pib zib 2.as_u128**60.as_u128  "EiB" "exbibyte"

  # zebibyte unit
  #
  public type.zib units.byte_iec => units.byte_iec eib yib 2.as_u128**70.as_u128  "ZiB" "zebibyte"

  # yobibyte unit
  #
  public type.yib units.byte_iec => units.byte_iec zib rib 2.as_u128**80.as_u128  "YiB" "yobibyte"

  # robibyte unit
  #
  public type.rib units.byte_iec => units.byte_iec yib qib 2.as_u128**90.as_u128  "RiB" "robibyte"

  # quebibyte unit
  #
  public type.qib units.byte_iec => units.byte_iec rib nil 2.as_u128**100.as_u128 "QiB" "quebibyte"

last changed: 2026-02-23