How to resolve the algorithm Extreme floating point values step by step in the Wren programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Extreme floating point values step by step in the Wren programming language
Table of Contents
Problem Statement
The IEEE floating point specification defines certain 'extreme' floating point values such as minus zero, -0.0, a value distinct from plus zero; not a number, NaN; and plus and minus infinity. The task is to use expressions involving other 'normal' floating point values in your language to calculate these, (and maybe other), extreme floating point values in your language and assign them to variables. Print the values of these variables if possible; and show some arithmetic with these values and variables. If your language can directly enter these extreme floating point values then show it.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Extreme floating point values step by step in the Wren programming language
Source code in the wren programming language
// using pre-defined constants
var inf = Num.infinity
var negInf = -inf
var nan = Num.nan
var negZero = -0
System.print([inf, negInf, nan, negZero])
System.print([inf + inf, negInf + inf, nan * nan, negZero == 0])
System.print([inf/inf, negInf/2, nan + inf, negZero/0])
System.print()
// using values computed from other 'normal' values
var inf2 = 1 / 0
var negInf2 = -1 / 0
var nan2 = 0 / 0
// using built-in comparison operators
System.print(inf2 == inf)
System.print(negInf == negInf2)
System.print(nan == nan2)
System.print(nan == nan)
System.print()
// using object equality
System.print(Object.same(nan, nan))
System.print(Object.same(nan, nan2))
You may also check:How to resolve the algorithm Doubly-linked list/Traversal step by step in the Ring programming language
You may also check:How to resolve the algorithm Loops/Downward for step by step in the Retro programming language
You may also check:How to resolve the algorithm Base64 decode data step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Search a list step by step in the D programming language
You may also check:How to resolve the algorithm Sum of a series step by step in the Dyalect programming language