Java Primitive Numeric Types, Assignment, and Expressions: Data

Total Page:16

File Type:pdf, Size:1020Kb

Java Primitive Numeric Types, Assignment, and Expressions: Data Java Primitive Numeric Types, Assignment, and Expressions: Data Types, Variables, and Declarations • A data type refers to a kind of value that a language recognizes { For example, integers, real numbers, characters, Booleans (true/false), etc. • Primitive data types represent single values and are built into a language; i.e., they are given • Java primitive numeric data types: 1. Integral types (a) byte (b) int (c) short (d) long 2. Real types (NOTE: The text calls these decimal types) (a) float (b) double • What distinguishes the various data types of a given group is the amount of storage allocated for storage { The greater the amount of storage, the greater the precision and magnitude of the value { Precision refers to the accuracy with which a value can be represented { Magnitude refers to the largest (and smallest) value that can be represented • A variable represents a storage location in memory for a value { Identifiers are used to represent variables { By convention, user-defined Java variables start with a lower case letter 1 Java Primitive Numeric Types, Assignment, and Expressions: Data Types, Variables, and Declarations (2) • Variable declarations { Java is a strongly typed language ∗ This means that a variable can only store values of a single data type { Semantics: A variable declaration tells the compiler how much storage to set aside for the variable, and how values in that memory location are to be interpreted ∗ Remember: Everything stored in memory is binary - zeroes and ones ∗ How the binary code is interpreted depends on what the system expects to find in a location { Syntax for primitive variable declaration: ∗ For example: int radius, length, width; double circleArea; { Generally, put one declaration per line 2 Java Primitive Numeric Types, Assignment, and Expressions: Integral Types • Represent whole numbers: 2, 103, -47 • Stored as binary whole numbers 0 1 2 { 21310 represents 3 × 10 + 1 × 10 + 2 × 10 = 3 × 1 + 1 × 10 + 2 × 100 = 213 { Binary only uses digits 0 and 1 0 1 2 3 4 5 6 7 { 110101012 represents 1×2 +0×2 +1×2 +0×2 +1×2 +0×2 +1×2 +1×2 = 1 × 1 + 0 × 2 + 1 × 4 + 0 × 8 + 1 × 16 + 0 × 32 + 1 × 64 + 1 × 128 = 213 { Java allocates the following storage type bytes smallest largest byte 1 -128 127 short 2 -32768 32767 int 4 -2147483648 2147483647 long 8 -9223372036854775808 9223372036854775807 3 Java Primitive Numeric Types, Assignment, and Expressions: Floating Point Types • Represent numbers with decimal points: 3.0, 66.667, -32.5 • Internally stored using scientific notation 2 { 125:3310 represented as 1:2533 × 10 = 1:2533 × 100 −3 { 0:0041710 represented as 4:17 × 10 = 4:17 × :001 { Reals are known as floating point types because 0 1 2 3 125:3310 = 125:33 × 10 = 12:533 × 10 = 1:2533 × 10 = :12533 × 10 = ::: { Java allocates the following storage type bytes smallest largest float 4 −3:40282347 × 1038 3:40282347 × 1038 double 8 −1:797693134862 × 10308 1:797693134862 × 10308 { Note that while integer values represent exact whole numbers, floating point types are often approximations to the actual value ∗ While their format allows very large numbers to be represented, it also de- creases the precision of their representation 4 Java Primitive Numeric Types, Assignment, and Expressions: Assignment and Numeric Expressions • Assignment is the most basic instruction • Syntax: • For example: x = 10; • Left side often referred to as the lvalue of the assignment Right side often referred to as the rvalue of the assignment • Semantics: The expression is evaluated and the value is stored in the variable's storage location 5 Java Primitive Numeric Types, Assignment, and Expressions: Assignment and Numeric Expressions (2) • Numeric expressions can take a number of forms: 1. Literal { Literal is an actual value { Integer syntax: ∗ Note: · If the first digit is a zero, the integer will be interpreted as an octal integer (base 8) · If the first digit is an 0x, the integer will be interpreted as a hexadecimal integer (base 16) ∗ An optional plus or minus may precede the value { Simple float syntax: { A floating point literal may also be expressed in scientific notation: { NOTE: As of Java 7, numeric literals may include underscores for readability (not indicated on the above) E.g., 32 817 423 6 Java Primitive Numeric Types, Assignment, and Expressions: Numeric Assignment (3) { Suffix ∗ What data type does 3.41457 represent? · By default, floating point literals are interpreted as type double · By default, integral literals are interpreted as type int · To indicate a specific type, Java allows a suffix to be appended to a literal Suffix Meaning f float F d double D l long L · For example: 123L, 13.7F 2. Variable { The assignment copies the value of the variable on the right into the memory associated with the variable on the left 7 Java Primitive Numeric Types, Assignment, and Expressions: Numeric Assignment (4) 3. Named (symbolic) constant { Value that cannot be changed during program execution { Represented by an identifier, just like a variable { MUST be initialized at declaration { Syntax: { Convention: use all caps for identifier { For example: final double COMMISSION = 0.10; 4. Value-returning method calls { A method (also called functions or subprograms in other languages) are like mini programs that perform a task ∗ For right now, we will only be concerned with value-returning methods - ones that generate a value ∗ Also, we are only concerned with methods that are supplied by Java · Later on we'll discuss how to write your own methods ∗ To use a method, you call the method ∗ Call syntax: ∗ { The value produced by such a method will 'take the place' of the call { java.lang.Math provides a number of useful class methods for performing stan- dard math functions 8 Java Primitive Numeric Types, Assignment, and Expressions: Numeric Assignment (5) { The table below lists a number of useful Math methods grouped by function- ality; ∗ If arguments are labeled as numeric, they could be int, long, float, or double (all the same type for a given version) ∗ All calls are preceded by Math. Method** Function numeric abs(numeric x) absolute value of x numeric max(numeric x, numeric y) larger of x and y numeric min(numeric x, numeric y) smaller of x and y double ceil(double x) smallest whole number ≥ x double floor(double x) largest whole number ≤ x int round(float x) x rounded to the nearest whole number long round(double x) " double sin(double x) sine of x double cos(double x) cosine of x double tan(double x) tangent of x double toDegrees(double x) x converted to degrees double toRadians(double x) x converted to radians double pow(double x, double y) xy p double sqrt(double x) x p double cbrt(double x) 3 x double random() 0:0 ≤ value < 1:0 ** NOTE: trig functions are based on radians (And constants: ∗ Math.E ∗ Math.PI) { This package does not need to be imported to be used { For example: int x, y, larger; x = 25; y = 13; larger = Math.max(x, y); 9 Java Primitive Numeric Types, Assignment, and Expressions: Numeric Assignment (6) 5. Math.random() needs some explanation { As indicated, it returns a value between 0.0 and 1.0, but will never be exactly one { To generate an integer between m and n, (a) Call Math.random() (b) Multiply the result by the number of possible values between m and n (c) Add m to the result { For example, to generate a value between one and six (e.g., to simulate a die roll) double result; result = Math.random(); result = 6 * result; result = 1 + result; { The general formula is result = m + (m − n + 1) ∗ Math:random() 6. Arithmetic expressions { These involve a calculation involving arithmetic operators { Unary operators (1 operand): (a) + (b) - { Binary operators (2 operands): (a) + (b) - (c) * (multiplication) (d) / (division) (e) % (remainder) 10 Java Primitive Numeric Types, Assignment, and Expressions: Numeric Assignment (7) 7. Compound expressions { Involve more than one operator { Evaluation determined by associativity and precedence { Associativity ∗ Pertains to the direction a given operator evaluates ∗ Can be left or right { Precedence ∗ Pertains to order in which different operators are evaluated 11 Java Primitive Numeric Types, Assignment, and Expressions: Numeric Assignment (8) { Associativity and precedence chart Operator Type Precedence Operators Associativity Subexpression 16 () Postfix increment 15 ++ L and decrement −− Prefix increment 14 ++ R and decrement −− Unary 14 ! R + - Type cast 13 (type)R Multiplicative 12 * L / % Additive 11 + L - + (string catenation) Relational 9 < L > ≤ ≥ Equality 8 == L != Boolean AND 4 && L Boolean OR 3 jj L conditional 2 ?: R Assignment 1 = R += (etc) Operator types listed from highest to lowest precedence. L indicates left-to-right; R indicates right-to-left. 12 Java Primitive Numeric Types, Assignment, and Expressions: Numeric Assignment (9) 8. Increment and decrement operators { Operators: (a) ++ (b) −− { There are actually 4 of them ∗ 2 are postfix: (a) operand + + (b) operand − − ∗ 2 are prefix: (a) + + operand (b) − − operand { Postfix semantics: (a) operand = operand ± 1 (b) return value of operand { Prefix semantics: (a) return value of operand (b) operand = operand ± 1 9. "Special" assignment operators { These are shortcuts: (a) += (b) -= (c) *= (d) /= (e) %= { They all work in the same way ∗ Each combines an arithmetic operation with assignment ∗ Semantics of variable op = value: variable = variable op value 13 Java Primitive Numeric Types, Assignment, and Expressions: Mixed-Mode Expressions and Data Conversions • Operator overloading { Expression 5 + 2 uses integer addition { Expression 7:35 + 15:333 uses floating point addition { There are actually several versions of the '+' operator This is called operator overloading { How does Java handle 23:98 + 10? • Mixed-mode expressions involve 2 different data types • In order to perform the operation, the arguments must be made compatible so Java knows which version of '+' to use • Such changes in type are called type conversions • Java provides 2 approaches: implicit and explicit • Implicit { Java performs the conversion automatically { Argument of lesser precision is converted to the type of the argument with greater precision { Unary operator algorithm: 1.
Recommended publications
  • Metaobject Protocols: Why We Want Them and What Else They Can Do
    Metaobject protocols: Why we want them and what else they can do Gregor Kiczales, J.Michael Ashley, Luis Rodriguez, Amin Vahdat, and Daniel G. Bobrow Published in A. Paepcke, editor, Object-Oriented Programming: The CLOS Perspective, pages 101 ¾ 118. The MIT Press, Cambridge, MA, 1993. © Massachusetts Institute of Technology All rights reserved. No part of this book may be reproduced in any form by any electronic or mechanical means (including photocopying, recording, or information storage and retrieval) without permission in writing from the publisher. Metaob ject Proto cols WhyWeWant Them and What Else They Can Do App ears in Object OrientedProgramming: The CLOS Perspective c Copyright 1993 MIT Press Gregor Kiczales, J. Michael Ashley, Luis Ro driguez, Amin Vahdat and Daniel G. Bobrow Original ly conceivedasaneat idea that could help solve problems in the design and implementation of CLOS, the metaobject protocol framework now appears to have applicability to a wide range of problems that come up in high-level languages. This chapter sketches this wider potential, by drawing an analogy to ordinary language design, by presenting some early design principles, and by presenting an overview of three new metaobject protcols we have designed that, respectively, control the semantics of Scheme, the compilation of Scheme, and the static paral lelization of Scheme programs. Intro duction The CLOS Metaob ject Proto col MOP was motivated by the tension b etween, what at the time, seemed liketwo con icting desires. The rst was to have a relatively small but p owerful language for doing ob ject-oriented programming in Lisp. The second was to satisfy what seemed to b e a large numb er of user demands, including: compatibility with previous languages, p erformance compara- ble to or b etter than previous implementations and extensibility to allow further exp erimentation with ob ject-oriented concepts see Chapter 2 for examples of directions in which ob ject-oriented techniques might b e pushed.
    [Show full text]
  • Chapter 2 Basics of Scanning And
    Chapter 2 Basics of Scanning and Conventional Programming in Java In this chapter, we will introduce you to an initial set of Java features, the equivalent of which you should have seen in your CS-1 class; the separation of problem, representation, algorithm and program – four concepts you have probably seen in your CS-1 class; style rules with which you are probably familiar, and scanning - a general class of problems we see in both computer science and other fields. Each chapter is associated with an animating recorded PowerPoint presentation and a YouTube video created from the presentation. It is meant to be a transcript of the associated presentation that contains little graphics and thus can be read even on a small device. You should refer to the associated material if you feel the need for a different instruction medium. Also associated with each chapter is hyperlinked code examples presented here. References to previously presented code modules are links that can be traversed to remind you of the details. The resources for this chapter are: PowerPoint Presentation YouTube Video Code Examples Algorithms and Representation Four concepts we explicitly or implicitly encounter while programming are problems, representations, algorithms and programs. Programs, of course, are instructions executed by the computer. Problems are what we try to solve when we write programs. Usually we do not go directly from problems to programs. Two intermediate steps are creating algorithms and identifying representations. Algorithms are sequences of steps to solve problems. So are programs. Thus, all programs are algorithms but the reverse is not true.
    [Show full text]
  • Lecture 2: Variables and Primitive Data Types
    Lecture 2: Variables and Primitive Data Types MIT-AITI Kenya 2005 1 In this lecture, you will learn… • What a variable is – Types of variables – Naming of variables – Variable assignment • What a primitive data type is • Other data types (ex. String) MIT-Africa Internet Technology Initiative 2 ©2005 What is a Variable? • In basic algebra, variables are symbols that can represent values in formulas. • For example the variable x in the formula f(x)=x2+2 can represent any number value. • Similarly, variables in computer program are symbols for arbitrary data. MIT-Africa Internet Technology Initiative 3 ©2005 A Variable Analogy • Think of variables as an empty box that you can put values in. • We can label the box with a name like “Box X” and re-use it many times. • Can perform tasks on the box without caring about what’s inside: – “Move Box X to Shelf A” – “Put item Z in box” – “Open Box X” – “Remove contents from Box X” MIT-Africa Internet Technology Initiative 4 ©2005 Variables Types in Java • Variables in Java have a type. • The type defines what kinds of values a variable is allowed to store. • Think of a variable’s type as the size or shape of the empty box. • The variable x in f(x)=x2+2 is implicitly a number. • If x is a symbol representing the word “Fish”, the formula doesn’t make sense. MIT-Africa Internet Technology Initiative 5 ©2005 Java Types • Integer Types: – int: Most numbers you’ll deal with. – long: Big integers; science, finance, computing. – short: Small integers.
    [Show full text]
  • Kind of Quantity’
    NIST Technical Note 2034 Defning ‘kind of quantity’ David Flater This publication is available free of charge from: https://doi.org/10.6028/NIST.TN.2034 NIST Technical Note 2034 Defning ‘kind of quantity’ David Flater Software and Systems Division Information Technology Laboratory This publication is available free of charge from: https://doi.org/10.6028/NIST.TN.2034 February 2019 U.S. Department of Commerce Wilbur L. Ross, Jr., Secretary National Institute of Standards and Technology Walter Copan, NIST Director and Undersecretary of Commerce for Standards and Technology Certain commercial entities, equipment, or materials may be identifed in this document in order to describe an experimental procedure or concept adequately. Such identifcation is not intended to imply recommendation or endorsement by the National Institute of Standards and Technology, nor is it intended to imply that the entities, materials, or equipment are necessarily the best available for the purpose. National Institute of Standards and Technology Technical Note 2034 Natl. Inst. Stand. Technol. Tech. Note 2034, 7 pages (February 2019) CODEN: NTNOEF This publication is available free of charge from: https://doi.org/10.6028/NIST.TN.2034 NIST Technical Note 2034 1 Defning ‘kind of quantity’ David Flater 2019-02-06 This publication is available free of charge from: https://doi.org/10.6028/NIST.TN.2034 Abstract The defnition of ‘kind of quantity’ given in the International Vocabulary of Metrology (VIM), 3rd edition, does not cover the historical meaning of the term as it is most commonly used in metrology. Most of its historical meaning has been merged into ‘quantity,’ which is polysemic across two layers of abstraction.
    [Show full text]
  • Subtyping, Declaratively an Exercise in Mixed Induction and Coinduction
    Subtyping, Declaratively An Exercise in Mixed Induction and Coinduction Nils Anders Danielsson and Thorsten Altenkirch University of Nottingham Abstract. It is natural to present subtyping for recursive types coin- ductively. However, Gapeyev, Levin and Pierce have noted that there is a problem with coinductive definitions of non-trivial transitive inference systems: they cannot be \declarative"|as opposed to \algorithmic" or syntax-directed|because coinductive inference systems with an explicit rule of transitivity are trivial. We propose a solution to this problem. By using mixed induction and coinduction we define an inference system for subtyping which combines the advantages of coinduction with the convenience of an explicit rule of transitivity. The definition uses coinduction for the structural rules, and induction for the rule of transitivity. We also discuss under what condi- tions this technique can be used when defining other inference systems. The developments presented in the paper have been mechanised using Agda, a dependently typed programming language and proof assistant. 1 Introduction Coinduction and corecursion are useful techniques for defining and reasoning about things which are potentially infinite, including streams and other (poten- tially) infinite data types (Coquand 1994; Gim´enez1996; Turner 2004), process congruences (Milner 1990), congruences for functional programs (Gordon 1999), closures (Milner and Tofte 1991), semantics for divergence of programs (Cousot and Cousot 1992; Hughes and Moran 1995; Leroy and Grall 2009; Nakata and Uustalu 2009), and subtyping relations for recursive types (Brandt and Henglein 1998; Gapeyev et al. 2002). However, the use of coinduction can lead to values which are \too infinite”. For instance, a non-trivial binary relation defined as a coinductive inference sys- tem cannot include the rule of transitivity, because a coinductive reading of transitivity would imply that every element is related to every other (to see this, build an infinite derivation consisting solely of uses of transitivity).
    [Show full text]
  • Guide for the Use of the International System of Units (SI)
    Guide for the Use of the International System of Units (SI) m kg s cd SI mol K A NIST Special Publication 811 2008 Edition Ambler Thompson and Barry N. Taylor NIST Special Publication 811 2008 Edition Guide for the Use of the International System of Units (SI) Ambler Thompson Technology Services and Barry N. Taylor Physics Laboratory National Institute of Standards and Technology Gaithersburg, MD 20899 (Supersedes NIST Special Publication 811, 1995 Edition, April 1995) March 2008 U.S. Department of Commerce Carlos M. Gutierrez, Secretary National Institute of Standards and Technology James M. Turner, Acting Director National Institute of Standards and Technology Special Publication 811, 2008 Edition (Supersedes NIST Special Publication 811, April 1995 Edition) Natl. Inst. Stand. Technol. Spec. Publ. 811, 2008 Ed., 85 pages (March 2008; 2nd printing November 2008) CODEN: NSPUE3 Note on 2nd printing: This 2nd printing dated November 2008 of NIST SP811 corrects a number of minor typographical errors present in the 1st printing dated March 2008. Guide for the Use of the International System of Units (SI) Preface The International System of Units, universally abbreviated SI (from the French Le Système International d’Unités), is the modern metric system of measurement. Long the dominant measurement system used in science, the SI is becoming the dominant measurement system used in international commerce. The Omnibus Trade and Competitiveness Act of August 1988 [Public Law (PL) 100-418] changed the name of the National Bureau of Standards (NBS) to the National Institute of Standards and Technology (NIST) and gave to NIST the added task of helping U.S.
    [Show full text]
  • PDF (Dissertation.Pdf)
    Kind Theory Thesis by Joseph R. Kiniry In Partial Fulfillment of the Requirements for the Degree of Doctor of Philosophy California Institute of Technology Pasadena, California 2002 (Defended 10 May 2002) ii © 2002 Joseph R. Kiniry All Rights Reserved iii Preface This thesis describes a theory for representing, manipulating, and reasoning about structured pieces of knowledge in open collaborative systems. The theory's design is motivated by both its general model as well as its target user commu- nity. Its model is structured information, with emphasis on classification, relative structure, equivalence, and interpretation. Its user community is meant to be non-mathematicians and non-computer scientists that might use the theory via computational tool support once inte- grated with modern design and development tools. This thesis discusses a new logic called kind theory that meets these challenges. The core of the work is based in logic, type theory, and universal algebras. The theory is shown to be efficiently implementable, and several parts of a full realization have already been constructed and are reviewed. Additionally, several software engineering concepts, tools, and technologies have been con- structed that take advantage of this theoretical framework. These constructs are discussed as well, from the perspectives of general software engineering and applied formal methods. iv Acknowledgements I am grateful to my initial primary adviser, Prof. K. Mani Chandy, for bringing me to Caltech and his willingness to let me explore many unfamiliar research fields of my own choosing. I am also appreciative of my second adviser, Prof. Jason Hickey, for his support, encouragement, feedback, and patience through the later years of my work.
    [Show full text]
  • OMG Meta Object Facility (MOF) Core Specification
    Date : October 2019 OMG Meta Object Facility (MOF) Core Specification Version 2.5.1 OMG Document Number: formal/2019-10-01 Standard document URL: https://www.omg.org/spec/MOF/2.5.1 Normative Machine-Readable Files: https://www.omg.org/spec/MOF/20131001/MOF.xmi Informative Machine-Readable Files: https://www.omg.org/spec/MOF/20131001/CMOFConstraints.ocl https://www.omg.org/spec/MOF/20131001/EMOFConstraints.ocl Copyright © 2003, Adaptive Copyright © 2003, Ceira Technologies, Inc. Copyright © 2003, Compuware Corporation Copyright © 2003, Data Access Technologies, Inc. Copyright © 2003, DSTC Copyright © 2003, Gentleware Copyright © 2003, Hewlett-Packard Copyright © 2003, International Business Machines Copyright © 2003, IONA Copyright © 2003, MetaMatrix Copyright © 2015, Object Management Group Copyright © 2003, Softeam Copyright © 2003, SUN Copyright © 2003, Telelogic AB Copyright © 2003, Unisys USE OF SPECIFICATION - TERMS, CONDITIONS & NOTICES The material in this document details an Object Management Group specification in accordance with the terms, conditions and notices set forth below. This document does not represent a commitment to implement any portion of this specification in any company's products. The information contained in this document is subject to change without notice. LICENSES The companies listed above have granted to the Object Management Group, Inc. (OMG) a nonexclusive, royalty-free, paid up, worldwide license to copy and distribute this document and to modify this document and distribute copies of the modified version. Each of the copyright holders listed above has agreed that no person shall be deemed to have infringed the copyright in the included material of any such copyright holder by reason of having used the specification set forth herein or having conformed any computer software to the specification.
    [Show full text]
  • Software II: Principles of Programming Languages
    Software II: Principles of Programming Languages Lecture 6 – Data Types Some Basic Definitions • A data type defines a collection of data objects and a set of predefined operations on those objects • A descriptor is the collection of the attributes of a variable • An object represents an instance of a user- defined (abstract data) type • One design issue for all data types: What operations are defined and how are they specified? Primitive Data Types • Almost all programming languages provide a set of primitive data types • Primitive data types: Those not defined in terms of other data types • Some primitive data types are merely reflections of the hardware • Others require only a little non-hardware support for their implementation The Integer Data Type • Almost always an exact reflection of the hardware so the mapping is trivial • There may be as many as eight different integer types in a language • Java’s signed integer sizes: byte , short , int , long The Floating Point Data Type • Model real numbers, but only as approximations • Languages for scientific use support at least two floating-point types (e.g., float and double ; sometimes more • Usually exactly like the hardware, but not always • IEEE Floating-Point Standard 754 Complex Data Type • Some languages support a complex type, e.g., C99, Fortran, and Python • Each value consists of two floats, the real part and the imaginary part • Literal form real component – (in Fortran: (7, 3) imaginary – (in Python): (7 + 3j) component The Decimal Data Type • For business applications (money)
    [Show full text]
  • A Core Calculus of Metaclasses
    A Core Calculus of Metaclasses Sam Tobin-Hochstadt Eric Allen Northeastern University Sun Microsystems Laboratories [email protected] [email protected] Abstract see the problem, consider a system with a class Eagle and Metaclasses provide a useful mechanism for abstraction in an instance Harry. The static type system can ensure that object-oriented languages. But most languages that support any messages that Harry responds to are also understood by metaclasses impose severe restrictions on their use. Typi- any other instance of Eagle. cally, a metaclass is allowed to have only a single instance However, even in a language where classes can have static and all metaclasses are required to share a common super- methods, the desired relationships cannot be expressed. For class [6]. In addition, few languages that support metaclasses example, in such a language, we can write the expression include a static type system, and none include a type system Eagle.isEndangered() provided that Eagle has the ap- with nominal subtyping (i.e., subtyping as defined in lan- propriate static method. Such a method is appropriate for guages such as the JavaTM Programming Language or C#). any class that is a species. However, if Salmon is another To elucidate the structure of metaclasses and their rela- class in our system, our type system provides us no way of tionship with static types, we present a core calculus for a requiring that it also have an isEndangered method. This nominally typed object-oriented language with metaclasses is because we cannot classify both Salmon and Eagle, when and prove type soundness over this core.
    [Show full text]
  • Fpnew: an Open-Source Multi-Format Floating-Point Unit Architecture For
    1 FPnew: An Open-Source Multi-Format Floating-Point Unit Architecture for Energy-Proportional Transprecision Computing Stefan Mach, Fabian Schuiki, Florian Zaruba, Student Member, IEEE, and Luca Benini, Fellow, IEEE Abstract—The slowdown of Moore’s law and the power wall Internet of Things (IoT) domain. In this environment, achiev- necessitates a shift towards finely tunable precision (a.k.a. trans- ing high energy efficiency in numerical computations requires precision) computing to reduce energy footprint. Hence, we need architectures and circuits which are fine-tunable in terms of circuits capable of performing floating-point operations on a wide range of precisions with high energy-proportionality. We precision and performance. Such circuits can minimize the present FPnew, a highly configurable open-source transprecision energy cost per operation by adapting both performance and floating-point unit (TP-FPU) capable of supporting a wide precision to the application requirements in an agile way. The range of standard and custom FP formats. To demonstrate the paradigm of “transprecision computing” [1] aims at creating flexibility and efficiency of FPnew in general-purpose processor a holistic framework ranging from algorithms and software architectures, we extend the RISC-V ISA with operations on half-precision, bfloat16, and an 8bit FP format, as well as SIMD down to hardware and circuits which offer many knobs to vectors and multi-format operations. Integrated into a 32-bit fine-tune workloads. RISC-V core, our TP-FPU can speed up execution of mixed- The most flexible and dynamic way of performing nu- precision applications by 1.67x w.r.t.
    [Show full text]
  • Polymorphic Subtyping in O'haskell
    Science of Computer Programming 43 (2002) 93–127 www.elsevier.com/locate/scico Polymorphic subtyping in O’Haskell Johan Nordlander Department of Computer Science and Engineering, Oregon Graduate Institute of Science and Technology, 20000 NW Walker Road, Beaverton, OR 97006, USA Abstract O’Haskell is a programming language derived from Haskell by the addition of concurrent reactive objects and subtyping. Because Haskell already encompasses an advanced type system with polymorphism and overloading, the type system of O’Haskell is much richer than what is the norm in almost any widespread object-oriented or functional language. Yet, there is strong evidence that O’Haskell is not a complex language to use, and that both Java and Haskell pro- grammers can easily ÿnd their way with its polymorphic subtyping system. This paper describes the type system of O’Haskell both formally and from a programmer’s point of view; the latter task is accomplished with the aid of an illustrative, real-world programming example: a strongly typed interface to the graphical toolkit Tk. c 2002 Elsevier Science B.V. All rights reserved. Keywords: Type inference; Subtyping; Polymorphism; Haskell; Graphical toolkit 1. Introduction The programming language O’Haskell is the result of a ÿnely tuned combination of ideas and concepts from functional, object-oriented, and concurrent programming, that has its origin in the purely functional language Haskell [36]. The name O’Haskell is a tribute to this parentage, where the O should be read as an indication of Objects,as well as a reactive breach with the tradition that views Input as an active operation on par with Output.
    [Show full text]