How to resolve the algorithm Extreme floating point values step by step in the Clojure programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Extreme floating point values step by step in the Clojure 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 Clojure programming language

Source code in the clojure programming language

(def neg-inf (/ -1.0 0.0)) ; Also Double/NEGATIVE_INFINITY
(def inf (/ 1.0 0.0))      ; Also Double/POSITIVE_INFINITY
(def nan (/ 0.0 0.0))      ; Also Double/NaN
(def neg-zero (/ -2.0 Double/POSITIVE_INFINITY))   ; Also -0.0
(println "  Negative inf: " neg-inf)
(println "  Positive inf: " inf)
(println "           NaN: " nan)
(println "    Negative 0: " neg-zero)
(println "    inf + -inf: " (+ inf neg-inf))
(println "    NaN == NaN: " (= Double/NaN Double/NaN))
(println "NaN equals NaN: " (.equals Double/NaN Double/NaN))


  

You may also check:How to resolve the algorithm Sort using a custom comparator step by step in the Euphoria programming language
You may also check:How to resolve the algorithm List comprehensions step by step in the Ruby programming language
You may also check:How to resolve the algorithm Lychrel numbers step by step in the D programming language
You may also check:How to resolve the algorithm Stirling numbers of the first kind step by step in the Nim programming language
You may also check:How to resolve the algorithm Strip a set of characters from a string step by step in the F# programming language