April 02, 2020, 11:08:30 AM

Author Topic: float values with a e (-2.02805e-008) meaning and rounding ?  (Read 812 times)

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1039
float values with a e (-2.02805e-008) meaning and rounding ?
« on: October 03, 2019, 11:47:31 AM »
hi,

can somebody please remind me what these float values with a e mean :
(these are triangle normals)
Code: [Select]
triangle0 : -1.0,0.0,0.0
triangle1 : -1.0,0.0,0.0
triangle2 : 0.0,0.0,-1.0
triangle3 : 0.0,0.0,-1.0
triangle4 : 1.0,0.0,0.0
triangle5 : 1.0,0.0,0.0
triangle6 : 0.0,0.0,1.0
triangle7 : 0.0,0.0,1.0
triangle8 : 0.0,-1.0,0.0
triangle9 : 0.0,-1.0,0.0
triangle10 : 0.0,1.0,3.05176e-008
triangle11 : 0.0,1.0,3.05176e-008
triangle12 : -0.92388,-2.02805e-008,0.382683
triangle13 : -0.92388,-2.37601e-008,0.382683
triangle14 : -0.382683,-5.7362e-008,0.92388
triangle15 : -0.382683,-5.67855e-008,0.92388
triangle16 : 0.382683,-5.67855e-008,0.92388
triangle17 : 0.382683,-5.7362e-008,0.92388
triangle18 : 0.92388,-2.09095e-008,0.382683
triangle19 : 0.92388,-2.43366e-008,0.382683
triangle20 : 0.92388,2.02805e-008,-0.382683
triangle21 : 0.92388,2.37601e-008,-0.382683
triangle22 : 0.382683,5.7362e-008,-0.92388
triangle23 : 0.382683,5.67855e-008,-0.92388
triangle24 : -0.382683,5.67855e-008,-0.92388
triangle25 : -0.382683,5.7362e-008,-0.92388
triangle26 : -0.92388,2.09095e-008,-0.382683
triangle27 : -0.92388,2.43366e-008,-0.382683
triangle28 : 0.0,1.0,0.0
triangle29 : 0.0,1.0,0.0
triangle30 : 0.0,1.0,0.0
triangle31 : 0.0,1.0,0.0
triangle32 : 0.0,1.0,0.0
triangle33 : 0.0,1.0,0.0
and how i can round them so that they stay readable and easy to debug ?

thanks,
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline Derron

  • Hero Member
  • *****
  • Posts: 2818
Re: float values with a e (-2.02805e-008) meaning and rounding ?
« Reply #1 on: October 03, 2019, 02:09:06 PM »
the 1.0e-1 would just mean: move everything one to the right: 0.1

so 8.2e-1 means 0.82.


3.05176e-008 so becomes 0.0000000305176


bye
Ron

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1039
Re: float values with a e (-2.02805e-008) meaning and rounding ?
« Reply #2 on: October 03, 2019, 03:40:26 PM »
@Ron>> ok thank you, so i don't have to consider the two 0 before the "exposant"
example :
3.05176e-008 ("exposant" is -8)
and this would translate to value with 8 zeros before
0.0000000305176


ok, and to use these weird float values, or round them (but keep a float value), an approach i see would be to translate it to a string (if it is not already) and if exposant is less than 003, consider the value to be equal to 0 (for my case a triangle normal less than 0.01 should not matter...)
any other idea ?
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1039
Re: float values with a e (-2.02805e-008) meaning and rounding ?
« Reply #3 on: October 03, 2019, 03:52:02 PM »
in theory this should work to filter out the values between -0.01 and +0.01
Code: [Select]
If( nx > -0.01 And nx < +0.01  ) Then nx = 0
If( ny > -0.01 And ny < +0.01 ) Then ny = 0
If( nz > -0.01 And nz < +0.01 ) Then nz = 0
but for some reason, this does not...
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline Derron

  • Hero Member
  • *****
  • Posts: 2818
Re: float values with a e (-2.02805e-008) meaning and rounding ?
« Reply #4 on: October 03, 2019, 04:00:21 PM »
https://floating-point-gui.de/errors/comparison/


Aside of that: can't you multiply the number by a certain factor (your "details"). So if you only care for 3 digits, you multiply with 1000 and round.

0.00004 * 1000 = 0.04, as int then 0
0.004 * 1000 = 4, as int then 4 (which is not 0).


You could then do this:
If( int(nx*1000 + 0.5) = 0 ) Then nx = 0

-> the +0.5 is to also handle negative values of interest
-0.005 * 1000 + 0.5 => 4.5 -> as int 4, not filtered
+0.005 * 1000 + 0.5 => 5.5 -> as int 5, not filtered
-0.0001 * 1000 + 0.5 => 0.4 -> as int 0, filtered
+0.0001 * 1000 + 0.5 => 0.6 -> as int 0, filtered


Where do these numbers come from? it depends on how you print stuff, internally it is stored not with "e" / as text.


bye
Ron

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1039
Re: float values with a e (-2.02805e-008) meaning and rounding ?
« Reply #5 on: October 03, 2019, 04:22:55 PM »
i have coded this, and this works well, but it may be too slow for my procedure to calculate triangle normals (and filter out the values which are between -0.001 and +0.001)
Code: [Select]
;removed buggy code

well no it does not work as i want because if the value is 0.9991, again there is an exposant, but the value is not between -0.001 and +0.001... arg :-\
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1039
Re: float values with a e (-2.02805e-008) meaning and rounding ?
« Reply #6 on: October 03, 2019, 04:45:39 PM »
Quote
0.00004 * 1000 = 0.04, as int then 0
0.004 * 1000 = 4, as int then 4 (which is not 0).
oooh that's a good idea, thanks, going to try ;D
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1039
Re: float values with a e (-2.02805e-008) meaning and rounding ?
« Reply #7 on: October 03, 2019, 04:50:30 PM »
This works well, and should be fast, thanks Ron !

Code: [Select]
;rounds a float value to 0.001 or more else it becomes 0.0
;when you type/get 0.001, it stays 0.001, but when you type/get 0.0001 it becomes "1.0e-004"
;when you type/get "1.0e-004" it stays "1.0e-004", "but when you type 1.0e-003" it becomes 0.001
;the goal of this procedure is to get rid of all float values less than 0.001 so the e-004 or similar writing does not appear anymore which may cause errors in your code...
Graphics(854,480,32,2)

For i% = 1 To 100 Step 1
 F# = Rnd(0.0001,0.009) ;try with values between 0.0001 and 0.009, only the values of 0.001 or more should be kept
 RF# = RoundFloat(F)
 DebugLog(F+"->"+RF)
Next

WaitKey()
End()

Function RoundFloat#(F#)
 FInt% = Int(F*1000)
 FRounded# = Float(FInt)/1000
 Return FRounded
End Function

outputs :
Code: [Select]
triangle0 : -1.0,0.0,0.0
triangle1 : -1.0,0.0,0.0
triangle2 : 0.0,0.0,-1.0
triangle3 : 0.0,0.0,-1.0
triangle4 : 1.0,0.0,0.0
triangle5 : 1.0,0.0,0.0
triangle6 : 0.0,0.0,1.0
triangle7 : 0.0,0.0,1.0
triangle8 : 0.0,-1.0,0.0
triangle9 : 0.0,-1.0,0.0
triangle10 : 0.0,1.0,0.0
triangle11 : 0.0,1.0,0.0
triangle12 : -0.924,0.0,0.383
triangle13 : -0.924,0.0,0.383
triangle14 : -0.383,0.0,0.924
triangle15 : -0.383,0.0,0.924
triangle16 : 0.383,0.0,0.924
triangle17 : 0.383,0.0,0.924
triangle18 : 0.924,0.0,0.383
triangle19 : 0.924,0.0,0.383
triangle20 : 0.924,0.0,-0.383
triangle21 : 0.924,0.0,-0.383
triangle22 : 0.383,0.0,-0.924
triangle23 : 0.383,0.0,-0.924
triangle24 : -0.383,0.0,-0.924
triangle25 : -0.383,0.0,-0.924
triangle26 : -0.924,0.0,-0.383
triangle27 : -0.924,0.0,-0.383
triangle28 : 0.0,1.0,0.0
triangle29 : 0.0,1.0,0.0
triangle30 : 0.0,1.0,0.0
triangle31 : 0.0,1.0,0.0
triangle32 : 0.0,1.0,0.0
triangle33 : 0.0,1.0,0.0
8)
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline Derron

  • Hero Member
  • *****
  • Posts: 2818
Re: float values with a e (-2.02805e-008) meaning and rounding ?
« Reply #8 on: October 03, 2019, 06:51:05 PM »
there is of course a limit - pass a pretty big float and "* 1000" will reach the limit. So for that it might be better to use a "double".


bye
Ron

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal