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

Published on 12 May 2024 09:40 PM
#J

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

Source code in the j programming language

   Inf=: _
   NegInf=: __
   NB. Negative zero cannot be represented in J to be distinct from 0.
   NaN=. _.


   (1 % 0) , (_1 % 0)
_ __
   (1e234 * 1e234) , (_1e234 * 1e234)
_ __
   _ + __         NB. generates NaN error, rather than NaN
|NaN error
|   _    +__

   _ - _          NB. generates NaN error, rather than NaN
|NaN error
|   _    -_
   %_
0
  %__             NB. Under the covers, the reciprocal of NegInf produces NegZero, but this fact isn't exposed to the user, who just sees zero
0


   _ + _
_
   __ + __
__
   Inf + 0
_
   NegInf * 0
0


  

You may also check:How to resolve the algorithm Percentage difference between images step by step in the Frink programming language
You may also check:How to resolve the algorithm Walk a directory/Recursively step by step in the Elixir programming language
You may also check:How to resolve the algorithm Pangram checker step by step in the Action! programming language
You may also check:How to resolve the algorithm Bernstein basis polynomials step by step in the Go programming language
You may also check:How to resolve the algorithm Accumulator factory step by step in the Icon and Unicon programming language