Unnecessary double checks of infinity

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Unnecessary double checks of infinity

SergeStinckwich
Hi all,
I'm having a look how floats are printed.
Why we check two times if a Float is infinite ?
A first time in:

Float>>printOn: stream base: base
...
self isInfinite
ifTrue: [
stream nextPutAll: 'Float infinity'.
^ self sign = -1 ifTrue: [ stream nextPutAll: ' negated' ] ].
...

and a second time in:

Float>>absPrintExactlyOn: aStream base: base
...
self isInfinite ifTrue: [
aStream nextPutAll: 'Float infinity'.
^ self].
...

the same in Float>>absPrintInexactlyOn: aStream base: base
...
self isInfinite ifTrue: [aStream nextPutAll: 'Float infinity'. ^ self].
...

Apparently the last two methods are never called when number is infinite.

I remove the second checks and apparently nothing breaks (all number tests are still green).

Regards,
--
Serge Stinckwic
h

Int. Research Unit
 on Modelling/Simulation of Complex Systems (UMMISCO)
Sorbonne University
 (SU)
French National Research Institute for Sustainable Development (IRD)
U
niversity of Yaoundé I, Cameroon
"Programs must be written for people to read, and only incidentally for machines to execute."
https://twitter.com/SergeStinckwich
Reply | Threaded
Open this post in threaded view
|

Re: Unnecessary double checks of infinity

SergeStinckwich

On Sun, Dec 22, 2019 at 5:12 PM Serge Stinckwich <[hidden email]> wrote:
Hi all,
I'm having a look how floats are printed.
Why we check two times if a Float is infinite ?
A first time in:

Float>>printOn: stream base: base
...
self isInfinite
ifTrue: [
stream nextPutAll: 'Float infinity'.
^ self sign = -1 ifTrue: [ stream nextPutAll: ' negated' ] ].
...

and a second time in:

Float>>absPrintExactlyOn: aStream base: base
...
self isInfinite ifTrue: [
aStream nextPutAll: 'Float infinity'.
^ self].
...

the same in Float>>absPrintInexactlyOn: aStream base: base
...
self isInfinite ifTrue: [aStream nextPutAll: 'Float infinity'. ^ self].
...

Apparently the last two methods are never called when number is infinite.

I remove the second checks and apparently nothing breaks (all number tests are still green).

Regards,
--
Serge Stinckwic
h

Int. Research Unit
 on Modelling/Simulation of Complex Systems (UMMISCO)
Sorbonne University
 (SU)
French National Research Institute for Sustainable Development (IRD)
U
niversity of Yaoundé I, Cameroon
"Programs must be written for people to read, and only incidentally for machines to execute."
https://twitter.com/SergeStinckwich


--
Serge Stinckwic
​h​

Int. Research Unit
 on Modelling/Simulation of Complex Systems (UMMISCO)
​Sorbonne University
 (SU)
French National Research Institute for Sustainable Development (IRD)​
U
​niversity of Yaoundé I​, Cameroon
"Programs must be written for people to read, and only incidentally for machines to execute."
https://twitter.com/SergeStinckwich